Bug 1013: Don't assume errno is between 0 and 100000
[elinks.git] / src / session / session.h
blobd32c38e534091f016e1790619e0309f4ee997b27
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,
40 /** This is generic frame descriptor, meaningful mainly for ses_*_frame*(). */
41 struct frame {
42 LIST_HEAD(struct frame);
44 unsigned char *name;
45 int redirect_cnt;
47 struct view_state vs;
50 /** Use for keyboard prefixes. */
51 struct kbdprefix {
52 /** This is the repeat count being inserted by user so far.
53 * It is stored intermediately per-session. */
54 int repeat_count;
56 #ifdef CONFIG_MARKS
57 /** If the previous key was a mark prefix, this describes what kind
58 * of action are we supposed to do when we receive the next key. */
59 enum { KP_MARK_NOTHING, KP_MARK_SET, KP_MARK_GOTO } mark;
60 #endif
63 struct session;
65 /** This describes, what are we trying to do right now. We pass this around so
66 * that we can use generic scheduler routines and when the control will get
67 * back to our subsystem, we will know what are we up to. */
68 enum task_type {
69 TASK_NONE,
70 TASK_FORWARD,
71 TASK_IMGMAP,
72 TASK_RELOAD,
73 TASK_HISTORY,
76 struct session_task {
77 enum task_type type;
78 /* TODO: union --pasky */
79 struct {
80 unsigned char *frame;
81 struct location *location;
82 } target;
85 struct session_status {
86 unsigned int show_tabs_bar:1;
87 unsigned int show_status_bar:1;
88 unsigned int show_title_bar:1;
90 int force_show_status_bar:2;
91 int force_show_title_bar:2;
93 unsigned int set_window_title:1;
94 unsigned char *last_title;
95 #ifdef CONFIG_ECMASCRIPT
96 unsigned char *window_status;
97 #endif
99 #ifdef CONFIG_LEDS
100 unsigned int show_leds:1;
101 struct led_panel leds;
102 struct led *ssl_led;
103 struct led *insert_mode_led;
104 struct led *ecmascript_led;
105 struct led *popup_led;
106 #endif
107 /** Has the tab been visited yet. */
108 unsigned int visited:1;
110 /** Is processing file requests. */
111 unsigned int processing_file_requests:1;
112 unsigned int show_tabs_bar_at_top:1;
115 enum insert_mode {
116 INSERT_MODE_LESS,
117 INSERT_MODE_ON,
118 INSERT_MODE_OFF,
121 enum navigate_mode {
122 NAVIGATE_LINKWISE,
123 NAVIGATE_CURSOR_ROUTING,
126 /** This is one of the building stones of ELinks architecture --- this structure
127 * carries information about the specific ELinks session. Each tab (thus, at
128 * least one per terminal, in the normal case) has its own session. Session
129 * describes mainly the current browsing and control state, from the currently
130 * viewed document through the browsing history of this session to the status
131 * bar information. */
132 struct session {
133 LIST_HEAD(struct session);
136 /** @name The vital session data
137 * @{ */
139 struct window *tab;
142 /** @} @name Browsing history
143 * @{ */
145 struct ses_history history;
148 /** @} @name The current document
149 * @{ */
151 LIST_OF(struct file_to_load) more_files;
153 struct download loading;
154 struct uri *loading_uri;
156 enum cache_mode reloadlevel;
157 int redirect_cnt;
159 struct document_view *doc_view;
160 LIST_OF(struct document_view) scrn_frames;
162 struct uri *download_uri;
164 /** The URI which is the referrer to the current loaded document
165 * or NULL if there are no referrer.
167 * The @c referrer member's sole purpose is to have the information
168 * handy when loading URIs. It is not 'filtered' in anyway at this
169 * level only at the lower ones. */
170 struct uri *referrer;
173 /** @} @name The current action-in-progress selector
174 * @{ */
176 struct session_task task;
179 /** @} @name The current browsing state
180 * @{ */
182 int search_direction;
183 struct kbdprefix kbdprefix;
184 int exit_query;
185 timer_id_T display_timer;
187 /** The text input form insert mode. It is a tristate controlled by the
188 * boolean document.browse.forms.insert_mode option. When disabled we
189 * use modeless insertion and we always insert stuff into the text
190 * input field. When enabled it is possible to switch insertion on and
191 * off using ::ACT_EDIT_ENTER and *_CANCEL. */
192 enum insert_mode insert_mode;
194 enum navigate_mode navigate_mode;
196 unsigned char *search_word;
197 unsigned char *last_search_word;
200 /** The possibly running type queries (what-to-do-with-that-file?) */
201 LIST_OF(struct type_query) type_queries;
203 /** The info for status displaying */
204 struct session_status status;
206 /** @} */
209 extern LIST_OF(struct session) sessions;
210 extern enum remote_session_flags remote_session_flags;
212 /** This returns a pointer to the current location inside of the given session.
213 * That's nice for encapsulation and already paid out once ;-). */
214 #define cur_loc(x) ((x)->history.current)
216 /** Return if we have anything being loaded in this session already.
217 * @relates session */
218 static inline int
219 have_location(struct session *ses) {
220 return !!cur_loc(ses);
223 /** Swaps the current session referrer with the new one passed as @a referrer.
224 * @a referrer may be NULL.
225 * @relates session */
226 void set_session_referrer(struct session *ses, struct uri *referrer);
228 void
229 print_error_dialog(struct session *ses, struct connection_state state,
230 struct uri *uri, enum connection_priority priority);
232 void process_file_requests(struct session *);
234 struct string *encode_session_info(struct string *info,
235 LIST_OF(struct string_list_item) *url_list);
237 /** @returns zero if the info was remote sessions or if it failed to
238 * create any sessions. */
239 int decode_session_info(struct terminal *term, struct terminal_info *info);
241 /** Registers a base session and returns its id. Value <= 0 means error. */
243 add_session_info(struct session *ses, struct uri *uri, struct uri *referrer,
244 enum cache_mode cache_mode, enum task_type task);
246 void done_saved_session_info(void);
248 struct session *init_session(struct session *ses, struct terminal *term,
249 struct uri *uri, int in_background);
251 void doc_loading_callback(struct download *, struct session *);
253 void abort_loading(struct session *, int);
254 void reload(struct session *, enum cache_mode);
255 void load_frames(struct session *, struct document_view *);
257 struct frame *ses_find_frame(struct session *, unsigned char *);
259 void free_files(struct session *);
260 void display_timer(struct session *ses);
262 /** session_is_loading() is like !!get_current_download() but doesn't take
263 * session.req_sent into account.
264 * @relates session */
265 int session_is_loading(struct session *ses);
266 struct download *get_current_download(struct session *ses);
268 /** Information about the current document */
269 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
270 unsigned char *get_current_title(struct session *, unsigned char *, size_t);
272 struct link *get_current_session_link(struct session *ses);
273 struct link *get_current_link_in_view(struct document_view *doc_view);
274 unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);
275 unsigned char *get_current_link_name(struct session *, unsigned char *, size_t);
277 extern LIST_OF(struct questions_entry) questions_queue;
278 void add_questions_entry(void (*callback)(struct session *, void *), void *data);
279 void check_questions_queue(struct session *ses);
281 unsigned char *get_homepage_url(void);
283 /** Returns current keyboard repeat count and reset it. */
284 int eat_kbd_repeat_count(struct session *ses);
286 #endif