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"
21 typedef void (download_callback_T
)(struct download
*, void *);
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
;
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
46 * These structures are kept in the session.type_queries list, and
47 * destroy_session() calls done_type_query() to destroy them too. */
49 LIST_HEAD(struct type_query
);
51 /** After ELinks has downloaded enough of the resource to see
52 * that a type query is needed, it moves the download here and
53 * continues it while the user decides what to do. */
54 struct download download
;
56 /** Cache entry loaded from #uri. Apparently used only for
57 * displaying the header. */
58 struct cache_entry
*cached
;
60 /** The session in which the user navigated to #uri. The
61 * type_query is in the session.type_queries list of this
65 /** The URI of the resource about which ELinks is asking.
66 * This reference must be released with done_uri(). */
69 /** The name of the frame in which the user navigated to #uri.
70 * If the user chooses to display the resource, it goes into
71 * this frame. This string must be freed with mem_free(). */
72 unsigned char *target_frame
;
74 /** Command line for an external handler, to be run when the
75 * download finishes. When ELinks displays the type query,
76 * it copies this from mime_handler.program of the default
77 * handler of the type. The user can then edit the string.
78 * This string must be freed with mem_free(). */
79 unsigned char *external_handler
;
81 /** Whether the external handler is going to use the terminal.
82 * When ELinks displays the type query, it copies this from
83 * mime_handler.block of the default handler of the type.
84 * The user can then change the flag with a checkbox. */
87 /** Whether the resource was generated by ELinks running
88 * a local CGI program. If the user chooses to open the
89 * resource with an external handler, ELinks normally saves
90 * the resource to a temporary file and passes the name of
91 * that to the external handler. However, if the resource is
92 * from a "file" URI that does not refer to a local CGI, then
93 * Elinks need not copy the file. */
99 struct file_download
{
100 OBJECT_HEAD(struct file_download
);
104 unsigned char *external_handler
;
106 struct terminal
*term
;
112 struct download download
;
114 /** Should the file be deleted when destroying the structure */
115 unsigned int delete:1;
117 /** Should the download be stopped/interrupted when destroying the structure */
120 /** Whether to block the terminal when running the external handler. */
121 unsigned int block
:1;
123 /** The current dialog for this download. Can be NULL. */
124 struct dialog_data
*dlg_data
;
125 struct listbox_item
*box_item
;
128 /** Stack of all running downloads */
129 extern LIST_OF(struct file_download
) downloads
;
132 is_in_downloads_list(struct file_download
*file_download
)
134 struct file_download
*down
;
136 foreach (down
, downloads
)
137 if (file_download
== down
) return 1;
142 int download_is_progressing(struct download
*download
);
144 int are_there_downloads(void);
146 /** Whether to resume downloading to a file. This is a bit mask.
147 * Unrecognized bits should be preserved and ignored. */
148 enum download_resume
{
149 /** Downloading cannot be resumed; do not offer such an option
150 * to the user. All bits clear. */
151 DOWNLOAD_RESUME_DISABLED
= 0,
153 /** Downloading can be resumed. This is the usual value. */
154 DOWNLOAD_RESUME_ALLOWED
= 1,
156 /** The user wants to resume downloading. This must not occur
157 * without DOWNLOAD_RESUME_ALLOWED. */
158 DOWNLOAD_RESUME_SELECTED
= 2
161 /** Type of the callback function that will be called when the file
162 * has been opened, or when it is known that the file will not be
166 * The terminal on which the callback should display any windows.
167 * Comes directly from the @a term argument of create_download_file().
170 * A file descriptor to the opened file, or -1 if the file will not be
171 * opened. If the @a real_file argument of create_download_file()
172 * was not NULL, the callback may read the name of this file from
176 * A pointer to any data that the callback cares about.
177 * Comes directly from the @a data argument of create_download_file().
180 * The same as the @a resume argument of create_download_file(),
181 * except the ::DOWNLOAD_RESUME_SELECTED bit will be changed to match
182 * what the user chose.
184 * @relates cdf_hop */
185 typedef void cdf_callback_T(struct terminal
*term
, int fd
,
186 void *data
, enum download_resume resume
);
188 void start_download(void *, unsigned char *);
189 void resume_download(void *, unsigned char *);
190 void create_download_file(struct terminal
*, unsigned char *, unsigned char **,
191 int, enum download_resume
, cdf_callback_T
*, void *);
193 void abort_all_downloads(void);
194 void destroy_downloads(struct session
*);
195 void detach_downloads_from_terminal(struct terminal
*);
197 int setup_download_handler(struct session
*, struct download
*, struct cache_entry
*, int);
199 void abort_download(struct file_download
*file_download
);
200 void done_type_query(struct type_query
*type_query
);
202 void tp_display(struct type_query
*type_query
);
203 void tp_save(struct type_query
*type_query
);
204 void tp_cancel(void *data
);
205 struct file_download
*init_file_download(struct uri
*uri
, struct session
*ses
, unsigned char *file
, int fd
);