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 *);
23 /** Flags controlling how to download a file. This is a bit mask.
24 * Unrecognized bits should be preserved and ignored. */
26 /** Downloading cannot be resumed; do not offer such an option
27 * to the user. All bits clear. */
28 DOWNLOAD_RESUME_DISABLED
= 0,
30 /** Downloading can be resumed. This is the usual value. */
31 DOWNLOAD_RESUME_ALLOWED
= 1,
33 /** The user wants to resume downloading. This must not occur
34 * without #DOWNLOAD_RESUME_ALLOWED. */
35 DOWNLOAD_RESUME_SELECTED
= 2,
37 /** The file will be opened in an external handler. */
42 /* XXX: order matters there, there's some hard initialization in
43 * src/session/session.c and src/viewer/text/view.c */
44 LIST_HEAD(struct download
);
46 struct connection
*conn
;
47 struct cache_entry
*cached
;
48 /** The callback is called when connection gets into a progress state,
49 * after it's over (in a result state), and also periodically after
50 * the download starts receiving some data. */
51 download_callback_T
*callback
;
53 struct progress
*progress
;
55 struct connection_state state
;
56 struct connection_state prev_error
;
57 enum connection_priority pri
;
60 /** The user has navigated to a resource that ELinks does not display
61 * automatically because of its MIME type, and ELinks is asking what
64 * These structures are kept in the session.type_queries list, and
65 * destroy_session() calls done_type_query() to destroy them too. */
67 LIST_HEAD(struct type_query
);
69 /** After ELinks has downloaded enough of the resource to see
70 * that a type query is needed, it moves the download here and
71 * continues it while the user decides what to do. */
72 struct download download
;
74 /** Cache entry loaded from #uri. Apparently used only for
75 * displaying the header. */
76 struct cache_entry
*cached
;
78 /** The session in which the user navigated to #uri. The
79 * type_query is in the session.type_queries list of this
83 /** The URI of the resource about which ELinks is asking.
84 * This reference must be released with done_uri(). */
87 /** The name of the frame in which the user navigated to #uri.
88 * If the user chooses to display the resource, it goes into
89 * this frame. This string must be freed with mem_free(). */
90 unsigned char *target_frame
;
92 /** Command line for an external handler, to be run when the
93 * download finishes. When ELinks displays the type query,
94 * it copies this from mime_handler.program of the default
95 * handler of the type. The user can then edit the string.
96 * This string must be freed with mem_free(). */
97 unsigned char *external_handler
;
99 /** Whether the external handler is going to use the terminal.
100 * When ELinks displays the type query, it copies this from
101 * mime_handler.block of the default handler of the type.
102 * The user can then change the flag with a checkbox. */
105 /** Whether the resource was generated by ELinks running
106 * a local CGI program. If the user chooses to open the
107 * resource with an external handler, ELinks normally saves
108 * the resource to a temporary file and passes the name of
109 * that to the external handler. However, if the resource is
110 * from a "file" URI that does not refer to a local CGI, then
111 * Elinks need not copy the file. */
117 struct file_download
{
118 OBJECT_HEAD(struct file_download
);
122 unsigned char *external_handler
;
124 struct terminal
*term
;
130 struct download download
;
132 /** Should the file be deleted when destroying the structure */
133 unsigned int delete:1;
135 /** Should the download be stopped/interrupted when destroying the structure */
138 /** Whether to block the terminal when running the external handler. */
139 unsigned int block
:1;
141 /** The current dialog for this download. Can be NULL. */
142 struct dialog_data
*dlg_data
;
143 struct listbox_item
*box_item
;
146 /** Stack of all running downloads */
147 extern LIST_OF(struct file_download
) downloads
;
150 is_in_downloads_list(struct file_download
*file_download
)
152 struct file_download
*down
;
154 foreach (down
, downloads
)
155 if (file_download
== down
) return 1;
160 int download_is_progressing(struct download
*download
);
162 int are_there_downloads(void);
164 /** Type of the callback function that will be called when the file
165 * has been opened, or when it is known that the file will not be
169 * The terminal on which the callback should display any windows.
170 * Comes directly from the @a term argument of create_download_file().
173 * A file descriptor to the opened file, or -1 if the file will not be
174 * opened. If the @a real_file argument of create_download_file()
175 * was not NULL, the callback may read the name of this file from
179 * A pointer to any data that the callback cares about.
180 * Comes directly from the @a data argument of create_download_file().
183 * The same as the @a flags argument of create_download_file(),
184 * except the ::DOWNLOAD_RESUME_SELECTED bit will be changed to match
185 * what the user chose.
187 * @relates cdf_hop */
188 typedef void cdf_callback_T(struct terminal
*term
, int fd
,
189 void *data
, enum download_flags flags
);
191 void start_download(void *, unsigned char *);
192 void resume_download(void *, unsigned char *);
193 void create_download_file(struct terminal
*, unsigned char *, unsigned char **,
194 enum download_flags
, cdf_callback_T
*, void *);
196 void abort_all_downloads(void);
197 void destroy_downloads(struct session
*);
198 void detach_downloads_from_terminal(struct terminal
*);
200 int setup_download_handler(struct session
*, struct download
*, struct cache_entry
*, int);
202 void abort_download(struct file_download
*file_download
);
203 void done_type_query(struct type_query
*type_query
);
205 void tp_display(struct type_query
*type_query
);
206 void tp_save(struct type_query
*type_query
);
207 void tp_cancel(void *data
);
208 struct file_download
*init_file_download(struct uri
*uri
, struct session
*ses
, unsigned char *file
, int fd
);