Comment fixes
[elinks/elinks-j605.git] / src / session / download.h
blob0802fac199407e255c2e0518feb9a6ee117c0ca1
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 struct connection_state state;
38 struct connection_state prev_error;
39 enum connection_priority pri;
42 /** The user has navigated to a resource that ELinks does not display
43 * automatically because of its MIME type, and ELinks is asking what
44 * to do.
46 * These structures are kept in the session.type_queries list, and
47 * destroy_session() calls done_type_query() to destroy them too. */
48 struct type_query {
49 LIST_HEAD(struct type_query);
50 struct download download;
51 struct cache_entry *cached;
52 struct session *ses;
53 struct uri *uri;
54 unsigned char *target_frame;
55 unsigned char *external_handler;
56 int block;
58 /** Whether the resource was generated by ELinks running
59 * a local CGI program. If the user chooses to open the
60 * resource with an external handler, ELinks normally saves
61 * the resource to a temporary file and passes the name of
62 * that to the external handler. However, if the resource is
63 * from a "file" URI that does not refer to a local CGI, then
64 * Elinks need not copy the file. */
65 unsigned int cgi:1;
67 /* int frame; */
70 struct file_download {
71 OBJECT_HEAD(struct file_download);
73 struct uri *uri;
74 unsigned char *file;
75 unsigned char *external_handler;
76 struct session *ses;
77 struct terminal *term;
78 time_t remotetime;
79 off_t seek;
80 int handle;
81 int redirect_cnt;
82 int notify;
83 struct download download;
85 /** Should the file be deleted when destroying the structure */
86 unsigned int delete:1;
88 /** Should the download be stopped/interrupted when destroying the structure */
89 unsigned int stop:1;
91 /** Whether to block the terminal when running the external handler. */
92 unsigned int block:1;
94 /** The current dialog for this download. Can be NULL. */
95 struct dialog_data *dlg_data;
96 struct listbox_item *box_item;
99 /** Stack of all running downloads */
100 extern LIST_OF(struct file_download) downloads;
102 static inline int
103 is_in_downloads_list(struct file_download *file_download)
105 struct file_download *down;
107 foreach (down, downloads)
108 if (file_download == down) return 1;
110 return 0;
113 int download_is_progressing(struct download *download);
115 int are_there_downloads(void);
117 /** Whether to resume downloading to a file. This is a bit mask.
118 * Unrecognized bits should be preserved and ignored. */
119 enum download_resume {
120 /** Downloading cannot be resumed; do not offer such an option
121 * to the user. All bits clear. */
122 DOWNLOAD_RESUME_DISABLED = 0,
124 /** Downloading can be resumed. This is the usual value. */
125 DOWNLOAD_RESUME_ALLOWED = 1,
127 /** The user wants to resume downloading. This must not occur
128 * without DOWNLOAD_RESUME_ALLOWED. */
129 DOWNLOAD_RESUME_SELECTED = 2
132 /** Type of the callback function that will be called when the file
133 * has been opened, or when it is known that the file will not be
134 * opened.
136 * @param term
137 * The terminal on which the callback should display any windows.
138 * Comes directly from the @a term argument of create_download_file().
140 * @param fd
141 * A file descriptor to the opened file, or -1 if the file will not be
142 * opened. If the @a real_file argument of create_download_file()
143 * was not NULL, the callback may read the name of this file from
144 * *@a real_file.
146 * @param data
147 * A pointer to any data that the callback cares about.
148 * Comes directly from the @a data argument of create_download_file().
150 * @param resume
151 * The same as the @a resume argument of create_download_file(),
152 * except the ::DOWNLOAD_RESUME_SELECTED bit will be changed to match
153 * what the user chose.
155 * @relates cdf_hop */
156 typedef void cdf_callback_T(struct terminal *term, int fd,
157 void *data, enum download_resume resume);
159 void start_download(void *, unsigned char *);
160 void resume_download(void *, unsigned char *);
161 void create_download_file(struct terminal *, unsigned char *, unsigned char **,
162 int, enum download_resume, cdf_callback_T *, void *);
164 void abort_all_downloads(void);
165 void destroy_downloads(struct session *);
166 void detach_downloads_from_terminal(struct terminal *);
168 int setup_download_handler(struct session *, struct download *, struct cache_entry *, int);
170 void abort_download(struct file_download *file_download);
171 void done_type_query(struct type_query *type_query);
173 void tp_display(struct type_query *type_query);
174 void tp_save(struct type_query *type_query);
175 void tp_cancel(void *data);
176 struct file_download *init_file_download(struct uri *uri, struct session *ses, unsigned char *file, int fd);
178 #endif