Let users retry connection in case of error. Especially SSL error.
[elinks.git] / src / session / session.h
blob9f77b1413347c085da674aa516a2082788f3c016
1 #ifndef EL__SESSION_SESSION_H
2 #define EL__SESSION_SESSION_H
4 #include "bfu/dialog.h"
5 #include "cache/cache.h"
6 #include "main/timer.h" /* timer_id_T */
7 #include "network/state.h"
8 #include "session/download.h"
9 #include "session/history.h"
10 #include "util/lists.h"
11 #include "viewer/text/vs.h"
13 struct document_view;
14 struct link;
15 struct location;
16 struct session_status;
17 struct term_event;
18 struct terminal_info;
19 struct terminal;
20 struct uri;
21 struct window;
23 /** Used by delayed_open() and delayed_goto_uri_frame(). */
24 struct delayed_open {
25 struct session *ses;
26 struct uri *uri;
27 unsigned char *target;
30 enum remote_session_flags {
31 SES_REMOTE_NEW_TAB = 1,
32 SES_REMOTE_NEW_WINDOW = 2,
33 SES_REMOTE_CURRENT_TAB = 4,
34 SES_REMOTE_PROMPT_URL = 8,
35 SES_REMOTE_PING = 16,
36 SES_REMOTE_ADD_BOOKMARK = 32,
37 SES_REMOTE_INFO_BOX = 64,
38 SES_REMOTE_RELOAD = 128,
41 /** This is generic frame descriptor, meaningful mainly for ses_*_frame*(). */
42 struct frame {
43 LIST_HEAD(struct frame);
45 unsigned char *name;
46 int redirect_cnt;
48 struct view_state vs;
51 enum kp_mark { KP_MARK_NOTHING, KP_MARK_SET, KP_MARK_GOTO };
53 /** Use for keyboard prefixes. */
54 struct kbdprefix {
55 /** This is the repeat count being inserted by user so far.
56 * It is stored intermediately per-session. */
57 int repeat_count;
59 #ifdef CONFIG_MARKS
60 /** If the previous key was a mark prefix, this describes what kind
61 * of action are we supposed to do when we receive the next key. */
62 enum kp_mark mark;
63 #endif
66 struct session;
68 /** This describes, what are we trying to do right now. We pass this around so
69 * that we can use generic scheduler routines and when the control will get
70 * back to our subsystem, we will know what are we up to. */
71 enum task_type {
72 TASK_NONE,
73 TASK_FORWARD,
74 TASK_IMGMAP,
75 TASK_RELOAD,
76 TASK_HISTORY,
79 struct session_task {
80 enum task_type type;
81 /* TODO: union --pasky */
82 struct {
83 unsigned char *frame;
84 struct location *location;
85 } target;
88 struct session_status {
89 unsigned int show_tabs_bar:1;
90 unsigned int show_status_bar:1;
91 unsigned int show_title_bar:1;
93 int force_show_status_bar:2;
94 int force_show_title_bar:2;
96 unsigned int set_window_title:1;
97 unsigned char *last_title;
98 #ifdef CONFIG_ECMASCRIPT
99 unsigned char *window_status;
100 #endif
102 #ifdef CONFIG_LEDS
103 unsigned int show_leds:1;
104 struct led_panel leds;
105 struct led *ssl_led;
106 struct led *insert_mode_led;
107 struct led *ecmascript_led;
108 struct led *popup_led;
109 struct led *download_led;
110 #endif
111 /** Has the tab been visited yet. */
112 unsigned int visited:1;
114 /** Is processing file requests. */
115 unsigned int processing_file_requests:1;
116 unsigned int show_tabs_bar_at_top:1;
119 enum insert_mode {
120 INSERT_MODE_LESS,
121 INSERT_MODE_ON,
122 INSERT_MODE_OFF,
125 enum navigate_mode {
126 NAVIGATE_LINKWISE,
127 NAVIGATE_CURSOR_ROUTING,
130 /** This is one of the building stones of ELinks architecture --- this structure
131 * carries information about the specific ELinks session. Each tab (thus, at
132 * least one per terminal, in the normal case) has its own session. Session
133 * describes mainly the current browsing and control state, from the currently
134 * viewed document through the browsing history of this session to the status
135 * bar information. */
136 struct session {
137 LIST_HEAD(struct session);
140 #ifdef CONFIG_SCRIPTING_SPIDERMONKEY
141 struct JSObject *jsobject; /* Instance of session_class */
142 #endif
144 /** @name The vital session data
145 * @{ */
147 struct window *tab;
149 /* Session-specific options */
151 struct option *option;
154 /** @} @name Browsing history
155 * @{ */
157 struct ses_history history;
158 #ifdef CONFIG_SCRIPTING_SPIDERMONKEY
159 struct JSObject *history_jsobject; /* Instance of location_array_class */
160 #endif
163 /** @} @name The current document
164 * @{ */
166 LIST_OF(struct file_to_load) more_files;
168 struct download loading;
169 struct uri *loading_uri;
171 int reloadlevel;
172 int redirect_cnt;
174 struct document_view *doc_view;
175 LIST_OF(struct document_view) scrn_frames;
177 /** The URI from which the next start_download() or resume_download()
178 * call should download, or NULL if no such call is pending.
180 * When the user requests a download, one of those functions
181 * is given as a callback to query_file(), which asks the user
182 * where to save the downloaded file. The URI cannot be given
183 * to the callback as a parameter because query_file()
184 * supports only one void * parameter for the callback and
185 * that one is already used for the struct session *.
186 * Instead, the URI is saved here before the query_file()
187 * call. */
188 struct uri *download_uri;
190 /** The URI which is the referrer to the current loaded document
191 * or NULL if there are no referrer.
193 * The @c referrer member's sole purpose is to have the information
194 * handy when loading URIs. It is not 'filtered' in anyway at this
195 * level only at the lower ones. */
196 struct uri *referrer;
199 /** @} @name The current action-in-progress selector
200 * @{ */
202 struct session_task task;
205 /** @} @name The current browsing state
206 * @{ */
208 int search_direction;
209 struct kbdprefix kbdprefix;
210 int exit_query;
211 timer_id_T display_timer;
213 /** The text input form insert mode. It is a tristate controlled by the
214 * boolean document.browse.forms.insert_mode option. When disabled we
215 * use modeless insertion and we always insert stuff into the text
216 * input field. When enabled it is possible to switch insertion on and
217 * off using ::ACT_EDIT_ENTER and *_CANCEL. */
218 enum insert_mode insert_mode;
220 enum navigate_mode navigate_mode;
222 unsigned char *search_word;
223 unsigned char *last_search_word;
226 /** The possibly running type queries (what-to-do-with-that-file?) */
227 LIST_OF(struct type_query) type_queries;
229 /** The info for status displaying */
230 struct session_status status;
232 /** Verify SSL */
233 unsigned int verify:1;
234 /** @} */
237 extern LIST_OF(struct session) sessions;
238 extern enum remote_session_flags remote_session_flags;
240 /** This returns a pointer to the current location inside of the given session.
241 * That's nice for encapsulation and already paid out once ;-). */
242 #define cur_loc(x) ((x)->history.current)
244 /** Return if we have anything being loaded in this session already.
245 * @relates session */
246 static inline int
247 have_location(struct session *ses) {
248 return !!cur_loc(ses);
251 /** Swaps the current session referrer with the new one passed as @a referrer.
252 * @a referrer may be NULL.
253 * @relates session */
254 void set_session_referrer(struct session *ses, struct uri *referrer);
256 void
257 print_error_dialog(struct session *ses, struct connection_state state,
258 struct uri *uri, enum connection_priority priority);
260 void process_file_requests(struct session *);
262 struct string *encode_session_info(struct string *info,
263 LIST_OF(struct string_list_item) *url_list);
265 /** @returns zero if the info was remote sessions or if it failed to
266 * create any sessions. */
267 int decode_session_info(struct terminal *term, struct terminal_info *info);
269 /** Registers a base session and returns its id. Value <= 0 means error. */
271 add_session_info(struct session *ses, struct uri *uri, struct uri *referrer,
272 enum cache_mode cache_mode, enum task_type task);
274 void done_saved_session_info(void);
276 struct session *init_session(struct session *ses, struct terminal *term,
277 struct uri *uri, int in_background);
279 void doc_loading_callback(struct download *, struct session *);
281 void abort_loading(struct session *, int);
282 void reload_frame(struct session *, unsigned char *, enum cache_mode);
283 void reload(struct session *, enum cache_mode);
284 void load_frames(struct session *, struct document_view *);
286 struct frame *ses_find_frame(struct session *, unsigned char *);
288 void free_files(struct session *);
289 void display_timer(struct session *ses);
291 /** session_is_loading() is like !!get_current_download() but doesn't take
292 * session.req_sent into account.
293 * @relates session */
294 int session_is_loading(struct session *ses);
295 struct download *get_current_download(struct session *ses);
297 /** Information about the current document */
298 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
299 unsigned char *get_current_title(struct session *, unsigned char *, size_t);
301 struct link *get_current_session_link(struct session *ses);
302 struct link *get_current_link_in_view(struct document_view *doc_view);
303 unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);
304 unsigned char *get_current_link_name(struct session *, unsigned char *, size_t);
306 extern LIST_OF(struct questions_entry) questions_queue;
307 void add_questions_entry(void (*callback)(struct session *, void *), void *data);
308 void check_questions_queue(struct session *ses);
310 unsigned char *get_homepage_url(void);
312 /** Returns current keyboard repeat count and reset it. */
313 int eat_kbd_repeat_count(struct session *ses);
315 /** Set current keyboard repeat count to given value and update link
316 * highlighting and status bar. */
317 int set_kbd_repeat_count(struct session *ses, int new_count);
319 #endif