links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

links.h (80508B)


      1 /* links.h
      2  * (c) 2002 Mikulas Patocka, Karel 'Clock' Kulhavy, Petr 'Brain' Kulhavy,
      3  *          Martin 'PerM' Pergel
      4  * This file is a part of the Links program, released under GPL.
      5  */
      6 
      7 #define LINKS_COPYRIGHT                                                        \
      8 	"(C) 1999 - 2019 Mikulas Patocka\n(C) 2000 - 2019 Petr Kulhavy, "      \
      9 	"Karel Kulhavy, Martin Pergel"
     10 
     11 #include <dirent.h>
     12 #include <errno.h>
     13 #include <event.h>
     14 #include <fcntl.h>
     15 #include <grp.h>
     16 #include <netdb.h>
     17 #include <poll.h>
     18 #include <pwd.h>
     19 #include <search.h>
     20 #include <signal.h>
     21 #include <stdarg.h>
     22 #include <stddef.h>
     23 #include <stdio.h>
     24 #include <stdlib.h>
     25 #include <string.h>
     26 #include <sys/socket.h>
     27 #include <sys/stat.h>
     28 #include <sys/utsname.h>
     29 #include <sys/wait.h>
     30 #include <termios.h>
     31 #include <unistd.h>
     32 
     33 #include "os_dep.h"
     34 #include "setup.h"
     35 
     36 #include <arpa/inet.h>
     37 
     38 #include <openssl/ssl.h>
     39 
     40 #define longlong  long long
     41 #define ulonglong unsigned long long
     42 
     43 #define stringify_internal(arg) #arg
     44 #define stringify(arg)          stringify_internal(arg)
     45 
     46 #define array_elements(a) (sizeof(a) / sizeof(*a))
     47 
     48 #ifdef HAVE_POINTER_COMPARISON_BUG
     49 	#define DUMMY ((void *)1L)
     50 #else
     51 	#define DUMMY ((void *)-1L)
     52 #endif
     53 
     54 #define cast_const_char (const char *)
     55 #define cast_char       (char *)
     56 #define cast_uchar      (unsigned char *)
     57 
     58 enum ret { RET_OK, RET_ERROR, RET_SYNTAX };
     59 
     60 #define EINTRLOOPX(ret_, call_, x_)                                            \
     61 	do {                                                                   \
     62 		(ret_) = (call_);                                              \
     63 	} while ((ret_) == (x_) && errno == EINTR)
     64 
     65 #define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
     66 
     67 #define ENULLLOOP(ret_, call_)                                                 \
     68 	do {                                                                   \
     69 		errno = 0;                                                     \
     70 		(ret_) = (call_);                                              \
     71 	} while (!(ret_) && errno == EINTR)
     72 
     73 #define MAX_STR_LEN 1024
     74 
     75 #define BIN_SEARCH(entries, eq, ab, key, result)                               \
     76 	{                                                                      \
     77 		int s_ = 0, e_ = (entries)-1;                                  \
     78 		(result) = -1;                                                 \
     79 		while (s_ <= e_) {                                             \
     80 			int m_ = (int)(((unsigned)s_ + (unsigned)e_) / 2);     \
     81 			if (eq((m_), (key))) {                                 \
     82 				(result) = m_;                                 \
     83 				break;                                         \
     84 			}                                                      \
     85 			if (ab((m_), (key)))                                   \
     86 				e_ = m_ - 1;                                   \
     87 			else                                                   \
     88 				s_ = m_ + 1;                                   \
     89 		}                                                              \
     90 	}
     91 
     92 void die(const char *, ...);
     93 void usage(void);
     94 void *xmalloc(size_t);
     95 void *xrealloc(void *, size_t);
     96 void *xreallocarray(void *, size_t, size_t);
     97 #define internal   die
     98 #define error      die
     99 #define fatal_exit die
    100 
    101 /* error.c */
    102 
    103 #define overalloc_at(f, l)                                                     \
    104 	do {                                                                   \
    105 		fatal_exit(                                                    \
    106 		    "ERROR: attempting to allocate too large block at %s:%d",  \
    107 		    f, l);                                                     \
    108 	} while (1) /* while (1) is not a typo --- it's here to allow the      \
    109 	    compiler that doesn't know that fatal_exit doesn't return to do    \
    110 	    better optimizations */
    111 
    112 #define overalloc() overalloc_at(__FILE__, __LINE__)
    113 
    114 #define overflow()                                                             \
    115 	do {                                                                   \
    116 		fatal_exit("ERROR: arithmetic overflow at %s:%d", __FILE__,    \
    117 		           __LINE__);                                          \
    118 	} while (1)
    119 
    120 static inline int
    121 test_int_overflow(int x, int y, int *result)
    122 {
    123 	int z = *result = x + y;
    124 	return ~(x ^ y) & (x ^ z) & (int)(1U << (sizeof(unsigned int) * 8 - 1));
    125 }
    126 
    127 static inline int
    128 safe_add_function(int x, int y, unsigned char *file, int line)
    129 {
    130 	int ret;
    131 	if (test_int_overflow(x, y, &ret))
    132 		fatal_exit("ERROR: arithmetic overflow at %s:%d: %d + %d", file,
    133 		           line, (x), (y));
    134 	return ret;
    135 }
    136 
    137 #define safe_add(x, y)                                                         \
    138 	safe_add_function(x, y, (unsigned char *)__FILE__, __LINE__)
    139 
    140 void *mem_calloc(size_t size);
    141 
    142 unsigned char *memacpy(const unsigned char *src, size_t len);
    143 unsigned char *stracpy(const unsigned char *src);
    144 
    145 #define pr(code)                                                               \
    146 	if (1) {                                                               \
    147 		code;                                                          \
    148 	} else
    149 
    150 /* inline */
    151 
    152 #define ALLOC_GR 0x040 /* must be power of 2 */
    153 
    154 #define get_struct_(ptr, struc, entry)                                         \
    155 	((struc *)((char *)(ptr)-offsetof(struc, entry)))
    156 #define get_struct(ptr, struc, entry)                                          \
    157 	((void)(&get_struct_(ptr, struc, entry)->entry == (ptr)),              \
    158 	 get_struct_(ptr, struc, entry))
    159 
    160 struct list_head {
    161 	struct list_head *next;
    162 	struct list_head *prev;
    163 };
    164 
    165 #define list_struct(ptr, struc) get_struct(ptr, struc, list_entry)
    166 #define init_list(x)                                                           \
    167 	do {                                                                   \
    168 		(x).next = &(x);                                               \
    169 		(x).prev = &(x);                                               \
    170 	} while (0)
    171 #define list_empty(x) ((x).next == &(x))
    172 #define del_list_entry(x)                                                      \
    173 	do {                                                                   \
    174 		(x)->next->prev = (x)->prev;                                   \
    175 		(x)->prev->next = (x)->next;                                   \
    176 		(x)->prev = (x)->next = NULL;                                  \
    177 	} while (0)
    178 #define del_from_list(x) del_list_entry(&(x)->list_entry)
    179 #define add_after_list_entry(p, x)                                             \
    180 	do {                                                                   \
    181 		(x)->next = (p)->next;                                         \
    182 		(x)->prev = (p);                                               \
    183 		(p)->next = (x);                                               \
    184 		(x)->next->prev = (x);                                         \
    185 	} while (0)
    186 #define add_before_list_entry(p, x)                                            \
    187 	do {                                                                   \
    188 		(x)->prev = (p)->prev;                                         \
    189 		(x)->next = (p);                                               \
    190 		(p)->prev = (x);                                               \
    191 		(x)->prev->next = (x);                                         \
    192 	} while (0)
    193 #define add_to_list(l, x)     add_after_list_entry(&(l), &(x)->list_entry)
    194 #define add_to_list_end(l, x) add_before_list_entry(&(l), &(x)->list_entry)
    195 #define add_after_pos(p, x)                                                    \
    196 	add_after_list_entry(&(p)->list_entry, &(x)->list_entry)
    197 #define add_before_pos(p, x)                                                   \
    198 	add_before_list_entry(&(p)->list_entry, &(x)->list_entry)
    199 #define fix_list_after_realloc(x)                                              \
    200 	do {                                                                   \
    201 		(x)->list_entry.prev->next = &(x)->list_entry;                 \
    202 		(x)->list_entry.next->prev = &(x)->list_entry;                 \
    203 	} while (0)
    204 #define foreachfrom(struc, e, h, l, s)                                         \
    205 	for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1);    \
    206 	     (h) = (h)->next)
    207 #define foreach(struc, e, h, l) foreachfrom (struc, e, h, l, (l).next)
    208 #define foreachbackfrom(struc, e, h, l, s)                                     \
    209 	for ((h) = (s); (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1);    \
    210 	     (h) = (h)->prev)
    211 #define foreachback(struc, e, h, l) foreachbackfrom (struc, e, h, l, (l).prev)
    212 #define free_list(struc, l)                                                    \
    213 	do {                                                                   \
    214 		while (!list_empty(l)) {                                       \
    215 			struc *a__ = list_struct((l).next, struc);             \
    216 			del_from_list(a__);                                    \
    217 			free(a__);                                             \
    218 		}                                                              \
    219 	} while (0)
    220 
    221 static inline int
    222 list_size(struct list_head *l)
    223 {
    224 	struct list_head *e;
    225 	int n = 0;
    226 	for (e = l->next; e != l; e = e->next)
    227 		n++;
    228 	return n;
    229 }
    230 
    231 #define list_entry_1st   struct list_head list_entry
    232 #define init_list_1st(x) { (x), (x) },
    233 
    234 #define WHITECHAR(x)                                                           \
    235 	((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
    236 #define U(x) ((x) == '"' || (x) == '\'')
    237 
    238 enum ci {
    239 	CI_BYTES = 1,
    240 	CI_FILES,
    241 	CI_LOCKED,
    242 	CI_LOADING,
    243 	CI_TIMERS,
    244 	CI_TRANSFER,
    245 	CI_CONNECTING,
    246 	CI_KEEP
    247 };
    248 
    249 /* string.c */
    250 
    251 int cmpbeg(const unsigned char *str, const unsigned char *b);
    252 int snprint(unsigned char *s, int n, int num);
    253 int snzprint(unsigned char *s, int n, off_t num);
    254 int xstrcmp(const unsigned char *s1, const unsigned char *s2);
    255 void add_to_strn(unsigned char **s, unsigned char *a);
    256 void extend_str(unsigned char **s, int n);
    257 
    258 size_t add_bytes_to_str(unsigned char **, size_t, unsigned char *, size_t);
    259 size_t add_to_str(unsigned char **, size_t, unsigned char *);
    260 size_t add_chr_to_str(unsigned char **, size_t, unsigned char);
    261 void add_unsigned_num_to_str(unsigned char **s, int *l, off_t n);
    262 void add_unsigned_long_num_to_str(unsigned char **s, int *l, unsigned long n);
    263 size_t add_num_to_str(unsigned char **s, size_t l, off_t n);
    264 size_t add_knum_to_str(unsigned char **s, size_t l, off_t n);
    265 long strtolx(unsigned char *c, unsigned char **end);
    266 
    267 void safe_strncpy(unsigned char *dst, const unsigned char *src,
    268                   size_t dst_size);
    269 int casestrcmp(const unsigned char *s1, const unsigned char *s2);
    270 int casecmp(const unsigned char *c1, const unsigned char *c2, size_t len);
    271 int casestrstr(const unsigned char *h, const unsigned char *n);
    272 
    273 /* os_dep.c */
    274 
    275 typedef unsigned long long uttime;
    276 typedef unsigned long long tcount;
    277 
    278 extern int page_size;
    279 
    280 struct terminal;
    281 
    282 struct open_in_new {
    283 	unsigned char *text;
    284 	unsigned char *hk;
    285 	int (*const *open_window_fn)(struct terminal *, unsigned char *,
    286 	                             unsigned char *);
    287 };
    288 
    289 void close_fork_tty(void);
    290 int is_screen(void);
    291 int is_xterm(void);
    292 void get_terminal_size(int *, int *);
    293 void handle_terminal_resize(void (*)(int, int), int *x, int *y);
    294 void unhandle_terminal_resize(void);
    295 void set_nonblock(int);
    296 int c_pipe(int[2]);
    297 int c_dup(int oh);
    298 int c_socket(int, int, int);
    299 int c_accept(int, struct sockaddr *, socklen_t *);
    300 int c_open(unsigned char *, int);
    301 int c_open3(unsigned char *, int, int);
    302 DIR *c_opendir(unsigned char *);
    303 #ifdef OS_SETRAW
    304 int setraw(int ctl, int save);
    305 #endif
    306 int start_thread(void (*)(void *, int), void *, int, int);
    307 unsigned char *get_clipboard_text(struct terminal *);
    308 void set_clipboard_text(struct terminal *, unsigned char *);
    309 int clipboard_support(struct terminal *);
    310 void set_window_title(unsigned char *);
    311 unsigned char *get_window_title(void);
    312 int is_safe_in_shell(unsigned char);
    313 unsigned char *escape_path(char *);
    314 void check_shell_security(unsigned char **);
    315 void check_filename(unsigned char **);
    316 int check_shell_url(unsigned char *);
    317 void do_signal(int sig, void (*handler)(int));
    318 uttime get_time(void);
    319 uttime get_absolute_time(void);
    320 void init_page_size(void);
    321 void ignore_signals(void);
    322 int os_get_system_name(unsigned char *buffer);
    323 unsigned char *os_conv_to_external_path(unsigned char *, unsigned char *);
    324 unsigned char *os_fixup_external_program(unsigned char *);
    325 int exe(char *, int);
    326 struct open_in_new *get_open_in_new(int);
    327 
    328 void os_free_clipboard(void);
    329 
    330 void os_detach_console(void);
    331 
    332 /* memory.c */
    333 
    334 enum mem_sh { SH_CHECK_QUOTA, SH_FREE_SOMETHING, SH_FREE_ALL };
    335 
    336 #define ST_SOMETHING_FREED 1
    337 #define ST_CACHE_EMPTY     2
    338 
    339 #define MF_GPI 1
    340 
    341 int shrink_memory(int);
    342 void register_cache_upcall(int (*)(int), int, unsigned char *);
    343 void free_all_caches(void);
    344 int out_of_memory(void);
    345 
    346 /* select.c */
    347 
    348 #ifndef FD_SETSIZE
    349 	#define FD_SETSIZE (sizeof(fd_set) * 8)
    350 #endif
    351 
    352 #define NBIT(p) (sizeof((p)->fds_bits[0]) * 8)
    353 
    354 #ifndef FD_SET
    355 	#define FD_SET(n, p)                                                   \
    356 		((p)->fds_bits[(n) / NBIT(p)] |= (1 << ((n) % NBIT(p))))
    357 #endif
    358 #ifndef FD_CLR
    359 	#define FD_CLR(n, p)                                                   \
    360 		((p)->fds_bits[(n) / NBIT(p)] &= ~(1 << ((n) % NBIT(p))))
    361 #endif
    362 #ifndef FD_ISSET
    363 	#define FD_ISSET(n, p)                                                 \
    364 		((p)->fds_bits[(n) / NBIT(p)] & (1 << ((n) % NBIT(p))))
    365 #endif
    366 #ifndef FD_ZERO
    367 	#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
    368 #endif
    369 
    370 extern int terminate_loop;
    371 
    372 int can_write(int fd);
    373 int can_read(int fd);
    374 int can_read_timeout(int fd, int sec);
    375 int close_stderr(void);
    376 void restore_stderr(int);
    377 unsigned long select_info(int);
    378 void reinit_child(void);
    379 void select_loop(void (*)(void));
    380 void terminate_select(void);
    381 void register_bottom_half(void (*)(void *), void *);
    382 void unregister_bottom_half(void (*)(void *), void *);
    383 void check_bottom_halves(void);
    384 size_t add_event_string(unsigned char **, size_t, struct terminal *);
    385 struct timer;
    386 struct timer *install_timer(uttime, void (*)(void *), void *);
    387 void kill_timer(struct timer *);
    388 void portable_sleep(unsigned msec);
    389 
    390 #define H_READ  0
    391 #define H_WRITE 1
    392 
    393 void (*get_handler(int, int))(void *);
    394 void *get_handler_data(int);
    395 extern unsigned char *sh_file;
    396 extern int sh_line;
    397 void set_handlers_file_line(int, void (*)(void *), void (*)(void *), void *);
    398 #define set_handlers(a, b, c, d)                                               \
    399 	(sh_file = (unsigned char *)__FILE__, sh_line = __LINE__,              \
    400 	 set_handlers_file_line(a, b, c, d))
    401 void clear_events(int, int);
    402 extern int signal_pipe[2];
    403 void install_signal_handler(int, void (*)(void *), void *, int);
    404 void interruptible_signal(int sig, int in);
    405 void block_signals(int except1, int except2);
    406 void unblock_signals(void);
    407 void set_sigcld(void);
    408 
    409 /* dns.c */
    410 
    411 #define MAX_ADDRESSES 64
    412 
    413 struct host_address {
    414 	int af;
    415 	unsigned char addr[16];
    416 	unsigned scope_id;
    417 };
    418 
    419 struct lookup_result {
    420 	int n;
    421 	struct host_address a[MAX_ADDRESSES];
    422 };
    423 
    424 struct lookup_state {
    425 	struct lookup_result addr;
    426 	int addr_index;
    427 	int dont_try_more_servers;
    428 	int socks_port;
    429 	int target_port;
    430 };
    431 
    432 int numeric_ip_address(const char *name, char address[4]);
    433 int numeric_ipv6_address(const char *name, char address[16],
    434                          unsigned *scope_id);
    435 void rotate_addresses(struct lookup_result *);
    436 int find_host(char *, struct lookup_result *, void **, void (*)(void *, int),
    437               void *);
    438 int find_host_no_cache(char *, struct lookup_result *, void **,
    439                        void (*)(void *, int), void *);
    440 void kill_dns_request(void **);
    441 #if MAX_ADDRESSES > 1
    442 void dns_set_priority(char *, struct host_address *, int);
    443 #endif
    444 void dns_clear_host(char *);
    445 unsigned long dns_info(int type);
    446 unsigned char *print_address(struct host_address *);
    447 int ipv6_full_access(void);
    448 void init_dns(void);
    449 
    450 /* cache.c */
    451 
    452 struct cache_entry {
    453 	list_entry_1st;
    454 	unsigned char *head;
    455 	int http_code;
    456 	unsigned char *redirect;
    457 	off_t length;
    458 	off_t max_length;
    459 	int incomplete;
    460 	int tgc;
    461 	unsigned char *last_modified;
    462 	time_t expire_time; /* 0 never, 1 always */
    463 	off_t data_size;
    464 	struct list_head frag; /* struct fragment */
    465 	tcount count;
    466 	tcount count2;
    467 	int refcount;
    468 	unsigned char *decompressed;
    469 	size_t decompressed_len;
    470 	unsigned char *ip_address;
    471 	unsigned char *ssl_info;
    472 	unsigned char *ssl_authority;
    473 	unsigned char url[1];
    474 };
    475 
    476 struct fragment {
    477 	list_entry_1st;
    478 	off_t offset;
    479 	off_t length;
    480 	off_t real_length;
    481 	unsigned char data[1];
    482 };
    483 
    484 struct connection;
    485 
    486 void init_cache(void);
    487 int cache_info(int);
    488 int decompress_info(int);
    489 int find_in_cache(unsigned char *, struct cache_entry **);
    490 int get_connection_cache_entry(struct connection *);
    491 int new_cache_entry(unsigned char *, struct cache_entry **);
    492 void detach_cache_entry(struct cache_entry *);
    493 int add_fragment(struct cache_entry *, off_t, const unsigned char *, off_t);
    494 int defrag_entry(struct cache_entry *);
    495 void truncate_entry(struct cache_entry *, off_t, int);
    496 void free_entry_to(struct cache_entry *, off_t);
    497 void delete_entry_content(struct cache_entry *);
    498 void delete_cache_entry(struct cache_entry *e);
    499 void trim_cache_entry(struct cache_entry *e);
    500 
    501 /* sched.c */
    502 
    503 typedef struct {
    504 	SSL *ssl;
    505 	SSL_CTX *ctx;
    506 	tcount bytes_read;
    507 	tcount bytes_written;
    508 	int session_set;
    509 	int session_retrieved;
    510 	unsigned char *ca;
    511 } links_ssl;
    512 
    513 enum pri {
    514 	PRI_MAIN,
    515 	PRI_DOWNLOAD,
    516 	PRI_FRAME,
    517 	PRI_NEED_IMG,
    518 	PRI_IMG,
    519 	PRI_PRELOAD,
    520 	PRI_CANCEL,
    521 	N_PRI
    522 };
    523 
    524 struct remaining_info {
    525 	int valid;
    526 	off_t size, loaded, last_loaded, cur_loaded;
    527 	off_t pos;
    528 	uttime elapsed;
    529 	uttime last_time;
    530 	uttime dis_b;
    531 	off_t data_in_secs[CURRENT_SPD_SEC];
    532 	struct timer *timer;
    533 };
    534 
    535 struct conn_info;
    536 
    537 struct connection {
    538 	list_entry_1st;
    539 	tcount count;
    540 	unsigned char *url;
    541 	unsigned char *prev_url; /* allocated string with referrer or NULL */
    542 	int running;
    543 	int state;
    544 	int prev_error;
    545 	off_t from;
    546 	int pri[N_PRI];
    547 	int no_cache;
    548 	int sock1;
    549 	int sock2;
    550 	void *dnsquery;
    551 	pid_t pid;
    552 	int tries;
    553 	int keepalive;
    554 	tcount netcfg_stamp;
    555 	struct list_head statuss;
    556 	void *info;
    557 	void *buffer;
    558 	struct conn_info *newconn;
    559 	void (*conn_func)(void *);
    560 	struct cache_entry *cache;
    561 	off_t received;
    562 	off_t est_length;
    563 	int unrestartable;
    564 	int no_compress;
    565 	struct remaining_info prg;
    566 	struct timer *timer;
    567 	int detached;
    568 	char socks_proxy[MAX_STR_LEN];
    569 	unsigned char dns_append[MAX_STR_LEN];
    570 	struct lookup_state last_lookup_state;
    571 	links_ssl *ssl;
    572 	int no_ssl_session;
    573 	int no_tls;
    574 };
    575 
    576 extern tcount netcfg_stamp;
    577 
    578 extern struct list_head queue;
    579 
    580 struct k_conn {
    581 	list_entry_1st;
    582 	void (*protocol)(struct connection *);
    583 	unsigned char *host;
    584 	int port;
    585 	int conn;
    586 	uttime timeout;
    587 	uttime add_time;
    588 	int protocol_data;
    589 	links_ssl *ssl;
    590 	struct lookup_state last_lookup_state;
    591 };
    592 
    593 extern struct list_head keepalive_connections;
    594 
    595 enum nc { NC_ALWAYS_CACHE, NC_CACHE, NC_IF_MOD, NC_RELOAD, NC_PR_NO_CACHE };
    596 
    597 enum ses {
    598 	S_WAIT,
    599 	S_DNS,
    600 	S_CONN,
    601 	S_CONN_ANOTHER,
    602 	S_SOCKS_NEG,
    603 	S_SSL_NEG,
    604 	S_SENT,
    605 	S_LOGIN,
    606 	S_GETH,
    607 	S_PROC,
    608 	S_TRANS
    609 };
    610 
    611 enum ses_sig {
    612 	S__OK = -2000000000,
    613 	S_INTERRUPTED,
    614 	S_INTERNAL,
    615 	S_OUT_OF_MEM,
    616 	S_NO_DNS,
    617 	S_NO_PROXY_DNS,
    618 	S_CANT_WRITE,
    619 	S_CANT_READ,
    620 	S_MODIFIED,
    621 	S_BAD_URL,
    622 	S_BAD_PROXY,
    623 	S_TIMEOUT,
    624 	S_RESTART,
    625 	S_STATE,
    626 	S_CYCLIC_REDIRECT,
    627 	S_LARGE_FILE,
    628 	S_SMB_NOT_ALLOWED,
    629 	S_FILE_NOT_ALLOWED,
    630 	S_NO_PROXY,
    631 
    632 	S_HTTP_ERROR = -2000000100,
    633 	S_HTTP_204,
    634 	S_HTTPS_FWD_ERROR,
    635 	S_INVALID_CERTIFICATE,
    636 	S_DOWNGRADED_METHOD,
    637 	S_INSECURE_CIPHER,
    638 
    639 	S_FILE_TYPE = -2000000200,
    640 	S_FILE_ERROR,
    641 
    642 	S_SSL_ERROR = -2000000400,
    643 	S_NO_SSL,
    644 
    645 	S_BAD_SOCKS_VERSION = -2000000500,
    646 	S_SOCKS_REJECTED,
    647 	S_SOCKS_NO_IDENTD,
    648 	S_SOCKS_BAD_USERID,
    649 	S_SOCKS_UNKNOWN_ERROR,
    650 
    651 	S_WAIT_REDIR,
    652 	S_UNKNOWN_ERROR,
    653 	S_MAX
    654 };
    655 
    656 struct status {
    657 	list_entry_1st;
    658 	struct connection *c;
    659 	struct cache_entry *ce;
    660 	int state;
    661 	int prev_error;
    662 	int pri;
    663 	void (*end)(struct status *, void *);
    664 	void *data;
    665 	struct remaining_info *prg;
    666 };
    667 
    668 int is_noproxy_url(unsigned char *url);
    669 unsigned char *get_proxy_string(unsigned char *url);
    670 unsigned char *get_proxy(unsigned char *url);
    671 int is_proxy_url(unsigned char *url);
    672 unsigned char *remove_proxy_prefix(unsigned char *url);
    673 int get_allow_flags(unsigned char *url);
    674 int disallow_url(unsigned char *url, int allow_flags);
    675 void check_queue(void *dummy);
    676 unsigned long connect_info(int);
    677 void setcstate(struct connection *c, int);
    678 int get_keepalive_socket(struct connection *c, int *protocol_data);
    679 void add_keepalive_socket(struct connection *c, uttime timeout,
    680                           int protocol_data);
    681 int is_connection_restartable(struct connection *c);
    682 int is_last_try(struct connection *c);
    683 void retry_connection(struct connection *c);
    684 void abort_connection(struct connection *c);
    685 #define ALLOW_SMB  1
    686 #define ALLOW_FILE 2
    687 #define ALLOW_ALL  (ALLOW_SMB | ALLOW_FILE)
    688 void load_url(unsigned char *, unsigned char *, struct status *, int, int, int,
    689               int, off_t);
    690 void change_connection(struct status *, struct status *, int);
    691 void detach_connection(struct status *, off_t, int, int);
    692 void abort_all_connections(void);
    693 int abort_background_connections(void);
    694 int is_entry_used(struct cache_entry *);
    695 void clear_connection_timeout(struct connection *);
    696 void set_connection_timeout(struct connection *);
    697 void set_connection_timeout_keepal(struct connection *);
    698 void add_blacklist_entry(unsigned char *, int);
    699 void del_blacklist_entry(unsigned char *, int);
    700 int get_blacklist_flags(unsigned char *);
    701 void free_blacklist(void);
    702 
    703 enum bl {
    704 	BL_HTTP10 = 0x001,
    705 	BL_NO_ACCEPT_LANGUAGE,
    706 	BL_NO_CHARSET,
    707 	BL_NO_RANGE,
    708 	BL_NO_COMPRESSION,
    709 	BL_NO_BZIP2,
    710 	BL_IGNORE_CERTIFICATE,
    711 	BL_IGNORE_DOWNGRADE,
    712 	BL_IGNORE_CIPHER,
    713 	BL_AVOID_INSECURE
    714 };
    715 
    716 /* suffix.c */
    717 
    718 int is_tld(unsigned char *name);
    719 int allow_cookie_domain(unsigned char *server, unsigned char *domain);
    720 
    721 /* url.c */
    722 
    723 struct session;
    724 
    725 #define POST_CHAR        1
    726 #define POST_CHAR_STRING "\001"
    727 
    728 static inline int
    729 end_of_dir(unsigned char *url, unsigned char c)
    730 {
    731 	return c == POST_CHAR || c == '#'
    732 	       || ((c == ';' || c == '?')
    733 	           && (!url || !casecmp(url, (unsigned char *)"http", 4)));
    734 }
    735 
    736 int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **,
    737               int *, unsigned char **, int *, unsigned char **, int *,
    738               unsigned char **, int *, unsigned char **);
    739 unsigned char *get_protocol_name(unsigned char *);
    740 unsigned char *get_host_name(unsigned char *);
    741 unsigned char *get_keepalive_id(unsigned char *);
    742 unsigned char *get_user_name(unsigned char *);
    743 unsigned char *get_pass(unsigned char *);
    744 int get_port(unsigned char *);
    745 unsigned char *get_port_str(unsigned char *);
    746 void (*get_protocol_handle(unsigned char *))(struct connection *);
    747 void (*get_external_protocol_function(unsigned char *))(struct session *,
    748                                                         unsigned char *);
    749 int url_bypasses_socks(unsigned char *);
    750 unsigned char *get_url_data(unsigned char *);
    751 int url_non_ascii(unsigned char *url);
    752 unsigned char *join_urls(unsigned char *, unsigned char *);
    753 unsigned char *translate_url(unsigned char *, unsigned char *);
    754 unsigned char *extract_position(unsigned char *);
    755 int url_not_saveable(unsigned char *);
    756 size_t add_conv_str(unsigned char **, size_t, unsigned char *, int, int);
    757 void convert_file_charset(unsigned char **s, int *l, int start_l);
    758 unsigned char *idn_encode_host(unsigned char *host, int len,
    759                                unsigned char *separator, int decode);
    760 unsigned char *idn_encode_url(unsigned char *url, int decode);
    761 unsigned char *display_url(struct terminal *term, unsigned char *url,
    762                            int warn_idn);
    763 unsigned char *display_host(struct terminal *term, unsigned char *host);
    764 unsigned char *display_host_list(struct terminal *term, unsigned char *host);
    765 
    766 /* connect.c */
    767 
    768 struct read_buffer {
    769 	int sock;
    770 	int len;
    771 	int close;
    772 	void (*done)(struct connection *, struct read_buffer *);
    773 	unsigned char data[1];
    774 };
    775 
    776 int socket_and_bind(int pf, unsigned char *address);
    777 void close_socket(int *);
    778 void make_connection(struct connection *, int, int *,
    779                      void (*)(struct connection *));
    780 void retry_connect(struct connection *, int, int);
    781 void continue_connection(struct connection *, int *,
    782                          void (*)(struct connection *));
    783 void write_to_socket(struct connection *, int, unsigned char *, int,
    784                      void (*)(struct connection *));
    785 struct read_buffer *alloc_read_buffer(void);
    786 void read_from_socket(struct connection *, int, struct read_buffer *,
    787                       void (*)(struct connection *, struct read_buffer *));
    788 void kill_buffer_data(struct read_buffer *, int);
    789 
    790 /* cookies.c */
    791 
    792 struct cookie {
    793 	list_entry_1st;
    794 	unsigned char *name, *value;
    795 	unsigned char *server;
    796 	unsigned char *path, *domain;
    797 	time_t expires; /* zero means undefined */
    798 	int secure;
    799 };
    800 
    801 struct c_domain {
    802 	list_entry_1st;
    803 	unsigned char domain[1];
    804 };
    805 
    806 extern struct list_head all_cookies;
    807 extern struct list_head c_domains;
    808 
    809 int set_cookie(struct terminal *, unsigned char *, unsigned char *);
    810 size_t add_cookies(unsigned char **, size_t, unsigned char *);
    811 void init_cookies(void);
    812 void free_cookies(void);
    813 int is_in_domain(unsigned char *d, unsigned char *s);
    814 int is_path_prefix(unsigned char *d, unsigned char *s);
    815 int cookie_expired(struct cookie *c);
    816 void free_cookie(struct cookie *c);
    817 
    818 /* auth.c */
    819 
    820 unsigned char *get_auth_realm(unsigned char *url, unsigned char *head,
    821                               int proxy);
    822 unsigned char *get_auth_string(unsigned char *url, int proxy);
    823 void free_auth(void);
    824 void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user,
    825               unsigned char *password, int proxy);
    826 int find_auth(unsigned char *url, unsigned char *realm);
    827 
    828 /* http.c */
    829 
    830 int get_http_code(unsigned char *head, int *code, int *version);
    831 unsigned char *parse_http_header(unsigned char *, unsigned char *,
    832                                  unsigned char **);
    833 unsigned char *parse_header_param(unsigned char *, unsigned char *, int);
    834 void http_func(struct connection *);
    835 void proxy_func(struct connection *);
    836 
    837 /* https.c */
    838 
    839 void https_func(struct connection *c);
    840 void ssl_finish(void);
    841 links_ssl *getSSL(void);
    842 void freeSSL(links_ssl *);
    843 int verify_ssl_certificate(links_ssl *ssl, unsigned char *host);
    844 int verify_ssl_cipher(links_ssl *ssl);
    845 int ssl_not_reusable(links_ssl *ssl);
    846 unsigned char *get_cipher_string(links_ssl *ssl);
    847 
    848 SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host,
    849                                      int port);
    850 void retrieve_ssl_session(struct connection *c);
    851 unsigned long session_info(int type);
    852 void init_session_cache(void);
    853 
    854 /* data.c */
    855 
    856 void data_func(struct connection *);
    857 
    858 /* file.c */
    859 
    860 void file_func(struct connection *);
    861 
    862 /* kbd.c */
    863 
    864 enum bm {
    865 	B_LEFT,
    866 	B_MIDDLE,
    867 	B_RIGHT,
    868 	B_FOURTH,
    869 	B_FIFTH,
    870 	B_SIXTH,
    871 	B_WHEELUP = 8,
    872 	B_WHEELDOWN,
    873 	B_WHEELUP1,
    874 	B_WHEELDOWN1,
    875 	B_WHEELLEFT,
    876 	B_WHEELRIGHT,
    877 	B_WHEELLEFT1,
    878 	B_WHEELRIGHT1
    879 };
    880 #define BM_BUTT B_WHEELRIGHT1
    881 
    882 #define BM_IS_WHEEL(b) ((b)&8)
    883 
    884 #define BM_ACT 48
    885 #define B_DOWN 0
    886 #define B_UP   16
    887 #define B_DRAG 32
    888 #define B_MOVE 48
    889 
    890 enum kbd {
    891 	KBD_SHIFT = (0 << 1),
    892 	KBD_CTRL = (0 << 2),
    893 	KBD_ALT = (0 << 3),
    894 	KBD_PASTING = (0 << 4),
    895 
    896 	KBD_ENTER = -0x100,
    897 	KBD_BS,
    898 	KBD_TAB,
    899 	KBD_ESC,
    900 	KBD_LEFT,
    901 	KBD_RIGHT,
    902 	KBD_UP,
    903 	KBD_DOWN,
    904 	KBD_INS,
    905 	KBD_DEL,
    906 	KBD_HOME,
    907 	KBD_END,
    908 	KBD_PAGE_UP,
    909 	KBD_PAGE_DOWN,
    910 	KBD_MENU,
    911 	KBD_STOP,
    912 
    913 	KBD_F1 = -0x120,
    914 	KBD_F2,
    915 	KBD_F3,
    916 	KBD_F4,
    917 	KBD_F5,
    918 	KBD_F6,
    919 	KBD_F7,
    920 	KBD_F8,
    921 	KBD_F9,
    922 	KBD_F10,
    923 	KBD_F11,
    924 	KBD_F12,
    925 
    926 	KBD_UNDO = -0x140,
    927 	KBD_REDO,
    928 	KBD_FIND,
    929 	KBD_HELP,
    930 	KBD_COPY,
    931 	KBD_PASTE,
    932 	KBD_CUT,
    933 	KBD_PROPS,
    934 	KBD_FRONT,
    935 	KBD_OPEN,
    936 	KBD_BACK,
    937 	KBD_FORWARD,
    938 	KBD_RELOAD,
    939 	KBD_BOOKMARKS,
    940 	KBD_SELECT,
    941 
    942 	KBD_CTRL_C = -0x200,
    943 	KBD_CLOSE
    944 };
    945 
    946 #define KBD_ESCAPE_MENU(x) ((x) <= KBD_F1 && (x) > KBD_CTRL_C)
    947 
    948 void handle_trm(int, void *, int);
    949 void free_all_itrms(void);
    950 void dispatch_special(unsigned char *);
    951 void kbd_ctrl_c(void);
    952 int is_blocked(void);
    953 
    954 struct itrm;
    955 
    956 extern unsigned char init_seq[];
    957 extern unsigned char init_seq_x_mouse[];
    958 extern unsigned char init_seq_tw_mouse[];
    959 extern unsigned char term_seq[];
    960 extern unsigned char term_seq_x_mouse[];
    961 extern unsigned char term_seq_tw_mouse[];
    962 
    963 struct rgb {
    964 	unsigned char r, g, b; /* This is 3*8 bits with sRGB gamma (in sRGB
    965 	                        * space) This is not rounded. */
    966 	unsigned char pad;
    967 };
    968 
    969 /* terminal.c */
    970 
    971 extern unsigned char frame_dumb[];
    972 
    973 typedef unsigned char_t;
    974 
    975 typedef struct {
    976 	char_t ch : 24;
    977 	unsigned char at;
    978 } chr;
    979 
    980 #define chr_has_padding (sizeof(chr) != 4)
    981 
    982 struct links_event {
    983 	int ev;
    984 	int x;
    985 	int y;
    986 	long b;
    987 };
    988 
    989 enum ev { EV_INIT, EV_KBD, EV_MOUSE, EV_EXTRA, EV_REDRAW, EV_RESIZE, EV_ABORT };
    990 #define EV_EXTRA_OPEN_URL EV_INIT
    991 
    992 enum evh {
    993 	EVH_NOT_PROCESSED,
    994 	EVH_LINK_KEYDOWN_PROCESSED,
    995 	EVH_LINK_KEYPRESS_PROCESSED,
    996 	EVH_DOCUMENT_KEYDOWN_PROCESSED,
    997 	EVH_DOCUMENT_KEYPRESS_PROCESSED
    998 };
    999 
   1000 struct window {
   1001 	list_entry_1st;
   1002 	void (*handler)(struct window *, struct links_event *, int fwd);
   1003 	void *data;
   1004 	int xp, yp;
   1005 	struct terminal *term;
   1006 };
   1007 
   1008 #define MAX_TERM_LEN 32 /* this must be multiple of 8! (alignment problems) */
   1009 
   1010 #define MAX_CWD_LEN                                                            \
   1011 	4096 /* this must be multiple of 8! (alignment problems)               \
   1012 	      */
   1013 
   1014 #define ENV_XWIN   1
   1015 #define ENV_SCREEN 2
   1016 
   1017 struct term_spec;
   1018 
   1019 struct terminal {
   1020 	list_entry_1st;
   1021 	tcount count;
   1022 
   1023 	int x;
   1024 	int y;
   1025 	/* text only */
   1026 	int master;
   1027 	int fdin;
   1028 	int fdout;
   1029 	int environment;
   1030 	unsigned char term[MAX_TERM_LEN];
   1031 	unsigned char cwd[MAX_CWD_LEN];
   1032 	chr *screen;
   1033 	chr *last_screen;
   1034 	struct term_spec *spec;
   1035 	int cx;
   1036 	int cy;
   1037 	int lcx;
   1038 	int lcy;
   1039 	int dirty;
   1040 	int redrawing;
   1041 	int blocked;
   1042 	unsigned char *input_queue;
   1043 	int qlen;
   1044 	int real_x;
   1045 	int real_y;
   1046 	int left_margin;
   1047 	int top_margin;
   1048 	/* end-of text only */
   1049 
   1050 	struct list_head windows;
   1051 	unsigned char *title;
   1052 
   1053 	int handle_to_close;
   1054 	unsigned char utf8_buffer[7];
   1055 	int utf8_paste_mode;
   1056 };
   1057 
   1058 struct term_spec {
   1059 	list_entry_1st;
   1060 	unsigned char term[MAX_TERM_LEN];
   1061 	int mode;
   1062 	int m11_hack;
   1063 	int restrict_852;
   1064 	int block_cursor;
   1065 	int col;
   1066 	int character_set;
   1067 	int left_margin;
   1068 	int right_margin;
   1069 	int top_margin;
   1070 	int bottom_margin;
   1071 };
   1072 
   1073 #define TERM_DUMB  0
   1074 #define TERM_VT100 1
   1075 
   1076 #define ATTR_FRAME 0x80
   1077 
   1078 extern struct list_head term_specs;
   1079 extern struct list_head terminals;
   1080 
   1081 #define term_charset(a) 0
   1082 
   1083 int hard_write(int, const unsigned char *, int);
   1084 int hard_read(int, unsigned char *, int);
   1085 unsigned char *get_cwd(void);
   1086 void set_cwd(unsigned char *);
   1087 unsigned char get_attribute(int, int);
   1088 struct terminal *
   1089 init_term(int, int, void (*)(struct window *, struct links_event *, int));
   1090 struct term_spec *new_term_spec(unsigned char *);
   1091 void free_term_specs(void);
   1092 void destroy_terminal(void *);
   1093 void cls_redraw_all_terminals(void);
   1094 void redraw_below_window(struct window *);
   1095 void add_window(struct terminal *,
   1096                 void (*)(struct window *, struct links_event *, int), void *);
   1097 void delete_window(struct window *);
   1098 void delete_window_ev(struct window *, struct links_event *ev);
   1099 void set_window_ptr(struct window *, int, int);
   1100 void get_parent_ptr(struct window *, int *, int *);
   1101 void add_empty_window(struct terminal *, void (*)(void *), void *);
   1102 void draw_to_window(struct window *, void (*)(struct terminal *, void *),
   1103                     void *);
   1104 void redraw_all_terminals(void);
   1105 void flush_terminal(struct terminal *);
   1106 
   1107 /* text only */
   1108 void set_char(struct terminal *, int, int, unsigned, unsigned char);
   1109 const chr *get_char(struct terminal *, int, int);
   1110 void set_color(struct terminal *, int, int, unsigned char);
   1111 void set_only_char(struct terminal *, int, int, unsigned, unsigned char);
   1112 void set_line(struct terminal *, int, int, int, chr *);
   1113 void set_line_color(struct terminal *, int, int, int, unsigned char);
   1114 void fill_area(struct terminal *, int, int, int, int, unsigned, unsigned char);
   1115 void draw_frame(struct terminal *, int, int, int, int, unsigned char, int);
   1116 void print_text(struct terminal *, int, int, int, unsigned char *,
   1117                 unsigned char);
   1118 void set_cursor(struct terminal *, int, int, int, int);
   1119 
   1120 void destroy_all_terminals(void);
   1121 void block_itrm(int);
   1122 int unblock_itrm(int);
   1123 
   1124 #define TERM_FN_TITLE  1
   1125 #define TERM_FN_RESIZE 2
   1126 
   1127 void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *,
   1128                       unsigned char);
   1129 void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
   1130 void set_terminal_title(struct terminal *, unsigned char *);
   1131 struct terminal *find_terminal(tcount count);
   1132 
   1133 /* language.c */
   1134 
   1135 #include "language.h"
   1136 
   1137 extern unsigned char dummyarray[];
   1138 
   1139 extern int current_language;
   1140 
   1141 unsigned char *get_text_translation(unsigned char *, struct terminal *term);
   1142 
   1143 #define TEXT_(x) (dummyarray + x) /* TEXT causes name clash on windows */
   1144 
   1145 /* main.c */
   1146 
   1147 extern int terminal_pipe[2];
   1148 
   1149 extern int retval;
   1150 
   1151 extern const char *argv0;
   1152 extern char **g_argv;
   1153 extern int g_argc;
   1154 
   1155 void sig_tstp(void *t);
   1156 void sig_cont(void *t);
   1157 
   1158 void unhandle_terminal_signals(struct terminal *term);
   1159 int attach_terminal(void *, int);
   1160 
   1161 /* objreq.c */
   1162 
   1163 #define O_WAITING    0
   1164 #define O_LOADING    1
   1165 #define O_FAILED     -1
   1166 #define O_INCOMPLETE -2
   1167 #define O_OK         -3
   1168 
   1169 struct object_request {
   1170 	list_entry_1st;
   1171 	int refcount;
   1172 	tcount count;
   1173 	tcount term;
   1174 	struct status stat;
   1175 	struct cache_entry *ce_internal;
   1176 	struct cache_entry *ce;
   1177 	unsigned char *orig_url;
   1178 	unsigned char *url;
   1179 	unsigned char *prev_url; /* allocated string with referrer or NULL */
   1180 	unsigned char *goto_position;
   1181 	int pri;
   1182 	int cache;
   1183 	void (*upcall)(struct object_request *, void *);
   1184 	void *data;
   1185 	int redirect_cnt;
   1186 	int state;
   1187 #define HOLD_AUTH 1
   1188 #define HOLD_CERT 2
   1189 	int hold;
   1190 	int dont_print_error;
   1191 	struct timer *timer;
   1192 
   1193 	off_t last_bytes;
   1194 
   1195 	uttime last_update;
   1196 };
   1197 
   1198 void request_object(struct terminal *, unsigned char *, unsigned char *, int,
   1199                     int, int, void (*)(struct object_request *, void *), void *,
   1200                     struct object_request **);
   1201 void clone_object(struct object_request *, struct object_request **);
   1202 void release_object(struct object_request **);
   1203 void release_object_get_stat(struct object_request **, struct status *, int);
   1204 void detach_object_connection(struct object_request *, off_t);
   1205 
   1206 /* compress.c */
   1207 
   1208 extern int decompressed_cache_size;
   1209 
   1210 int get_file_by_term(struct terminal *term, struct cache_entry *ce,
   1211                      unsigned char **start, size_t *len, int *errp);
   1212 int get_file(struct object_request *o, unsigned char **start, size_t *len);
   1213 void free_decompressed_data(struct cache_entry *e);
   1214 size_t add_compress_methods(unsigned char **, size_t);
   1215 
   1216 /* session.c */
   1217 
   1218 struct link_def {
   1219 	unsigned char *link;
   1220 	unsigned char *target;
   1221 
   1222 	unsigned char *label; /* only for image maps */
   1223 	unsigned char *shape;
   1224 	unsigned char *coords;
   1225 
   1226 	unsigned char *onclick;
   1227 	unsigned char *ondblclick;
   1228 	unsigned char *onmousedown;
   1229 	unsigned char *onmouseup;
   1230 	unsigned char *onmouseover;
   1231 	unsigned char *onmouseout;
   1232 	unsigned char *onmousemove;
   1233 };
   1234 
   1235 struct line {
   1236 	int l;
   1237 	int allocated;
   1238 	chr *d;
   1239 };
   1240 
   1241 struct point {
   1242 	int x;
   1243 	int y;
   1244 };
   1245 
   1246 struct form {
   1247 	unsigned char *action;
   1248 	unsigned char *target;
   1249 	unsigned char *form_name;
   1250 	unsigned char *onsubmit;
   1251 	int method;
   1252 	int num;
   1253 };
   1254 
   1255 enum fm { FM_GET, FM_POST, FM_POST_MP };
   1256 
   1257 enum fc {
   1258 	FC_TEXT = 1,
   1259 	FC_PASSWORD,
   1260 	FC_FILE_UPLOAD,
   1261 	FC_TEXTAREA,
   1262 	FC_CHECKBOX,
   1263 	FC_RADIO,
   1264 	FC_SELECT,
   1265 	FC_SUBMIT,
   1266 	FC_IMAGE,
   1267 	FC_RESET,
   1268 	FC_HIDDEN,
   1269 	FC_BUTTON
   1270 };
   1271 
   1272 struct menu_item;
   1273 
   1274 struct form_control {
   1275 	list_entry_1st;
   1276 	int form_num;   /* cislo formulare */
   1277 	int ctrl_num;   /* identifikace polozky v ramci formulare */
   1278 	int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v
   1279 	                   poli form_info) */
   1280 	int position;
   1281 	int method;
   1282 	unsigned char *action;
   1283 	unsigned char *target;
   1284 	unsigned char *onsubmit; /* script to be executed on submit */
   1285 	int type;
   1286 	unsigned char *name;
   1287 	unsigned char *form_name;
   1288 	unsigned char *alt;
   1289 	int ro;
   1290 	unsigned char *default_value;
   1291 	int default_state;
   1292 	int size;
   1293 	int cols, rows, wrap;
   1294 	int maxlength;
   1295 	int nvalues;            /* number of values in a select item */
   1296 	unsigned char **values; /* values of a select item */
   1297 	unsigned char **labels; /* labels (shown text) of a select item */
   1298 	struct menu_item *menu;
   1299 };
   1300 
   1301 struct line_info {
   1302 	int st_offs;
   1303 	int en_offs;
   1304 	int chars;
   1305 };
   1306 
   1307 struct format_text_cache_entry {
   1308 	int width;
   1309 	int wrap;
   1310 	int cp;
   1311 	int last_state;
   1312 	int last_vpos;
   1313 	int last_vypos;
   1314 	int last_cursor;
   1315 	int n_lines;
   1316 	struct line_info ln[1];
   1317 };
   1318 
   1319 struct form_state {
   1320 	int form_num;   /* cislo formulare */
   1321 	int ctrl_num;   /* identifikace polozky v ramci formulare */
   1322 	int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v
   1323 	                   poli form_info) */
   1324 	int position;
   1325 	int type;
   1326 	unsigned char *string; /* selected value of a select item */
   1327 	int state;             /* index of selected item of a select item */
   1328 	int vpos;
   1329 	int vypos;
   1330 	struct format_text_cache_entry *ftce;
   1331 };
   1332 
   1333 struct link {
   1334 	int type; /* one of L_XXX constants */
   1335 	int num;  /* link number (used when user turns on link numbering) */
   1336 	unsigned char *where;  /* URL of the link */
   1337 	unsigned char *target; /* name of target frame where to open the link */
   1338 	unsigned char *where_img; /* URL of image (if any) */
   1339 	unsigned char *img_alt; /* alt of image (if any) - valid only when link
   1340 	                           is an image */
   1341 	struct form_control *form; /* form info, usually NULL */
   1342 	unsigned sel_color;        /* link color */
   1343 	int n;                     /* number of points */
   1344 	int first_point_to_move;
   1345 	struct point *pos;
   1346 	int obj_order;
   1347 };
   1348 
   1349 enum l_link { L_LINK, L_BUTTON, L_CHECKBOX, L_SELECT, L_FIELD, L_AREA };
   1350 
   1351 struct link_bg {
   1352 	int x, y;
   1353 	unsigned char c;
   1354 };
   1355 
   1356 struct tag {
   1357 	list_entry_1st;
   1358 	int x;
   1359 	int y;
   1360 	unsigned char name[1];
   1361 };
   1362 
   1363 extern struct rgb palette_16_colors[16];
   1364 
   1365 /* when you add anything, don't forget to initialize it in default.c on line:
   1366  * struct document_setup dds = { ... };
   1367  */
   1368 struct document_setup {
   1369 	int assume_cp;
   1370 	int hard_assume;
   1371 	int tables;
   1372 	int frames;
   1373 	int break_long_lines;
   1374 	int images;
   1375 	int image_names;
   1376 	int margin;
   1377 	int num_links;
   1378 	int table_order;
   1379 	int auto_refresh;
   1380 	int font_size;
   1381 	int display_images;
   1382 	int image_scale;
   1383 	int porn_enable;
   1384 	int target_in_new_window;
   1385 	int t_text_color;
   1386 	int t_link_color;
   1387 	int t_background_color;
   1388 	int t_ignore_document_color;
   1389 	int g_text_color;
   1390 	int g_link_color;
   1391 	int g_background_color;
   1392 	int g_ignore_document_color;
   1393 };
   1394 
   1395 /* IMPORTANT!!!!!
   1396  * if you add anything, fix it in compare_opt and if you add it into
   1397  * document_setup, fix it in ds2do too
   1398  */
   1399 
   1400 struct document_options {
   1401 	int xw, yw; /* size of window */
   1402 	int xp, yp; /* pos of window */
   1403 	int scrolling;
   1404 	int col, cp, assume_cp, hard_assume;
   1405 	int tables, frames, break_long_lines, images, image_names, margin;
   1406 	int plain;
   1407 	int num_links, table_order;
   1408 	int auto_refresh;
   1409 	struct rgb default_fg;
   1410 	struct rgb default_bg;
   1411 	struct rgb default_link;
   1412 	unsigned char *framename;
   1413 	int font_size;
   1414 	int display_images;
   1415 	int image_scale;
   1416 	int porn_enable;
   1417 	tcount gamma_stamp;
   1418 	int real_cp; /* codepage of document. Does not really belong here. Must
   1419 	                not be compared. Used only in get_attr_val */
   1420 };
   1421 
   1422 static inline void
   1423 ds2do(struct document_setup *ds, struct document_options *doo, int col)
   1424 {
   1425 	doo->assume_cp = ds->assume_cp;
   1426 	doo->hard_assume = ds->hard_assume;
   1427 	doo->tables = ds->tables;
   1428 	doo->frames = ds->frames;
   1429 	doo->break_long_lines = ds->break_long_lines;
   1430 	doo->images = ds->images;
   1431 	doo->image_names = ds->image_names;
   1432 	doo->margin = ds->margin;
   1433 	doo->num_links = ds->num_links;
   1434 	doo->table_order = ds->table_order;
   1435 	doo->auto_refresh = ds->auto_refresh;
   1436 	doo->font_size = ds->font_size;
   1437 	doo->display_images = ds->display_images;
   1438 	doo->image_scale = ds->image_scale;
   1439 	doo->porn_enable = ds->porn_enable;
   1440 	if (!col) {
   1441 		doo->default_fg = palette_16_colors[7];
   1442 		doo->default_bg = palette_16_colors[0];
   1443 		doo->default_link = palette_16_colors[15];
   1444 	} else {
   1445 		doo->default_fg = palette_16_colors[ds->t_text_color];
   1446 		doo->default_bg = palette_16_colors[ds->t_background_color];
   1447 		doo->default_link = palette_16_colors[ds->t_link_color];
   1448 	}
   1449 }
   1450 
   1451 struct node {
   1452 	list_entry_1st;
   1453 	int x, y;
   1454 	int xw, yw;
   1455 };
   1456 
   1457 struct search {
   1458 	int idx;
   1459 	int x, y;
   1460 	unsigned short n;
   1461 	unsigned short co;
   1462 };
   1463 
   1464 struct frameset_desc;
   1465 
   1466 struct frame_desc {
   1467 	struct frameset_desc *subframe;
   1468 	unsigned char *name;
   1469 	unsigned char *url;
   1470 	int marginwidth;
   1471 	int marginheight;
   1472 	int line;
   1473 	int xw, yw;
   1474 	unsigned char scrolling;
   1475 };
   1476 
   1477 struct frameset_desc {
   1478 	int n;      /* = x * y */
   1479 	int x, y;   /* velikost */
   1480 	int xp, yp; /* pozice pri pridavani */
   1481 	struct frame_desc f[1];
   1482 };
   1483 
   1484 struct f_data;
   1485 
   1486 struct additional_file *request_additional_file(struct f_data *f,
   1487                                                 unsigned char *url);
   1488 
   1489 /*
   1490  * warning: if you add more additional file stuctures, you must
   1491  * set RQ upcalls correctly
   1492  */
   1493 
   1494 struct additional_files {
   1495 	int refcount;
   1496 	struct list_head af; /* struct additional_file */
   1497 };
   1498 
   1499 struct additional_file {
   1500 	list_entry_1st;
   1501 	struct object_request *rq;
   1502 	tcount use_tag;
   1503 	tcount use_tag2;
   1504 	int need_reparse;
   1505 	int unknown_image_size;
   1506 	unsigned char url[1];
   1507 };
   1508 
   1509 struct f_data {
   1510 	list_entry_1st;
   1511 	struct session *ses;
   1512 	struct f_data_c *fd;
   1513 	struct object_request *rq;
   1514 	tcount use_tag;
   1515 	struct additional_files *af;
   1516 	struct document_options opt;
   1517 	unsigned char *title;
   1518 	int cp, ass;
   1519 	int x, y; /* size of document */
   1520 	uttime time_to_get;
   1521 	uttime time_to_draw;
   1522 	struct frameset_desc *frame_desc;
   1523 	int frame_desc_link; /* if != 0, do not free frame_desc because it is
   1524 	                        link */
   1525 
   1526 	/* text only */
   1527 	int bg;
   1528 	struct line *data;
   1529 	struct link *links;
   1530 	int nlinks;
   1531 	struct link **lines1;
   1532 	struct link **lines2;
   1533 	struct list_head nodes; /* struct node */
   1534 	struct search *search_pos;
   1535 	char_t *search_chr;
   1536 	int nsearch_chr;
   1537 	int nsearch_pos;
   1538 	int *slines1;
   1539 	int *slines2;
   1540 
   1541 	struct list_head forms; /* struct form_control */
   1542 	struct list_head tags;  /* struct tag */
   1543 
   1544 	unsigned char *refresh;
   1545 	int refresh_seconds;
   1546 
   1547 	int uncacheable; /* cannot be cached - either created from source
   1548 	                    modified by document.write or modified by javascript
   1549 	                  */
   1550 };
   1551 
   1552 struct view_state {
   1553 	int refcount;
   1554 
   1555 	int view_pos;
   1556 	int view_posx;
   1557 	int orig_view_pos;
   1558 	int orig_view_posx;
   1559 	int current_link; /* platny jen kdyz je <f_data->n_links */
   1560 	int orig_link;
   1561 	int frame_pos;
   1562 	int plain;
   1563 	struct form_state *form_info;
   1564 	int form_info_len;
   1565 	int brl_x;
   1566 	int brl_y;
   1567 	int orig_brl_x;
   1568 	int orig_brl_y;
   1569 	int brl_in_field;
   1570 };
   1571 
   1572 struct location;
   1573 
   1574 struct f_data_c {
   1575 	list_entry_1st;
   1576 	struct f_data_c *parent;
   1577 	struct session *ses;
   1578 	struct location *loc;
   1579 	struct view_state *vs;
   1580 	struct f_data *f_data;
   1581 	int xw, yw; /* size of window */
   1582 	int xp, yp; /* pos of window on screen */
   1583 	int xl, yl; /* last pos of view in window */
   1584 
   1585 	int hsb, vsb;
   1586 	int hsbsize, vsbsize;
   1587 
   1588 	struct link_bg *link_bg;
   1589 	int link_bg_n;
   1590 	int depth;
   1591 
   1592 	struct object_request *rq;
   1593 	unsigned char *goto_position;
   1594 	unsigned char *went_to_position;
   1595 	struct additional_files *af;
   1596 
   1597 	struct list_head subframes; /* struct f_data_c */
   1598 
   1599 	uttime last_update;
   1600 	uttime next_update_interval;
   1601 	int done;
   1602 	int parsed_done;
   1603 	int script_t; /* offset of next script to execute */
   1604 
   1605 	int active; /* temporary, for draw_doc */
   1606 
   1607 	int marginwidth, marginheight;
   1608 
   1609 	struct timer *image_timer;
   1610 
   1611 	struct timer *refresh_timer;
   1612 
   1613 	unsigned char scrolling;
   1614 	unsigned char last_captured;
   1615 };
   1616 
   1617 struct location {
   1618 	list_entry_1st;
   1619 	struct location *parent;
   1620 	unsigned char *name; /* frame name */
   1621 	unsigned char *url;
   1622 	unsigned char *prev_url;    /* allocated string with referrer */
   1623 	struct list_head subframes; /* struct location */
   1624 	struct view_state *vs;
   1625 	unsigned location_id;
   1626 };
   1627 
   1628 #define cur_loc(x) list_struct((x)->history.next, struct location)
   1629 
   1630 struct kbdprefix {
   1631 	int rep;
   1632 	int rep_num;
   1633 	int prefix;
   1634 };
   1635 
   1636 struct download {
   1637 	list_entry_1st;
   1638 	unsigned char *url;
   1639 	struct status stat;
   1640 	unsigned char decompress;
   1641 	unsigned char *cwd;
   1642 	unsigned char *orig_file;
   1643 	unsigned char *file;
   1644 	off_t last_pos;
   1645 	off_t file_shift;
   1646 	int handle;
   1647 	int redirect_cnt;
   1648 	int downloaded_something;
   1649 	unsigned char *prog;
   1650 	int prog_flag_block;
   1651 	time_t remotetime;
   1652 	struct session *ses;
   1653 	struct window *win;
   1654 	struct window *ask;
   1655 };
   1656 
   1657 extern struct list_head downloads;
   1658 
   1659 struct session {
   1660 	list_entry_1st;
   1661 	struct list_head history; /* struct location */
   1662 	struct list_head forward_history;
   1663 	struct terminal *term;
   1664 	struct window *win;
   1665 	int id;
   1666 	unsigned char *st;     /* status line string */
   1667 	unsigned char *st_old; /* old status line --- compared with st to
   1668 	                          prevent cursor flicker */
   1669 	unsigned char *default_status; /* default value of the status line */
   1670 	struct f_data_c *screen;
   1671 	struct object_request *rq;
   1672 	void (*wtd)(struct session *);
   1673 	unsigned char *wtd_target;
   1674 	struct f_data_c *wtd_target_base;
   1675 	unsigned char *wanted_framename;
   1676 	int wtd_refresh;
   1677 	int wtd_num_steps;
   1678 	unsigned char *goto_position;
   1679 	struct document_setup ds;
   1680 	struct kbdprefix kbdprefix;
   1681 	int reloadlevel;
   1682 	struct object_request *tq;
   1683 	unsigned char *tq_prog;
   1684 	int tq_prog_flag_block;
   1685 	int tq_prog_flag_direct;
   1686 	unsigned char *dn_url;
   1687 	int dn_allow_flags;
   1688 	unsigned char *search_word;
   1689 	unsigned char *last_search_word;
   1690 	int search_direction;
   1691 	int exit_query;
   1692 	struct list_head format_cache; /* struct f_data */
   1693 
   1694 	unsigned char *imgmap_href_base;
   1695 	unsigned char *imgmap_target_base;
   1696 
   1697 	int brl_cursor_mode;
   1698 };
   1699 
   1700 struct dialog_data;
   1701 
   1702 int f_is_finished(struct f_data *f);
   1703 unsigned long formatted_info(int);
   1704 int shrink_format_cache(int u);
   1705 void init_fcache(void);
   1706 void html_interpret_recursive(struct f_data_c *);
   1707 void fd_loaded(struct object_request *, void *);
   1708 
   1709 extern struct list_head sessions;
   1710 
   1711 time_t parse_http_date(unsigned char *);
   1712 unsigned char *encode_url(unsigned char *);
   1713 unsigned char *decode_url(unsigned char *);
   1714 struct session *get_download_ses(struct download *);
   1715 unsigned char *subst_file(unsigned char *, unsigned char *, int);
   1716 int are_there_downloads(void);
   1717 unsigned char get_session_attribute(struct session *, int);
   1718 unsigned char *translate_download_file(unsigned char *);
   1719 void free_strerror_buf(void);
   1720 int get_error_from_errno(int errn);
   1721 unsigned char *get_err_msg(int);
   1722 void change_screen_status(struct session *);
   1723 void print_screen_status(struct session *);
   1724 void print_progress(struct session *, unsigned char *);
   1725 void print_error_dialog(struct session *, struct status *, unsigned char *);
   1726 void start_download(struct session *, unsigned char *, int);
   1727 int test_abort_downloads_to_file(unsigned char *, unsigned char *, int);
   1728 void abort_all_downloads(void);
   1729 unsigned char *download_percentage(struct download *down, int pad);
   1730 void download_window_function(struct dialog_data *dlg);
   1731 void display_download(struct terminal *, void *, void *);
   1732 struct f_data *cached_format_html(struct f_data_c *fd,
   1733                                   struct object_request *rq, unsigned char *url,
   1734                                   struct document_options *opt, int *cch,
   1735                                   int report_status);
   1736 struct f_data_c *create_f_data_c(struct session *, struct f_data_c *);
   1737 void reinit_f_data_c(struct f_data_c *);
   1738 int f_data_c_allow_flags(struct f_data_c *fd);
   1739 #define CDF_RESTRICT_PERMISSION 1
   1740 #define CDF_EXCL                2
   1741 #define CDF_NOTRUNC             4
   1742 #define CDF_NO_POPUP_ON_EEXIST  8
   1743 int create_download_file(struct session *, unsigned char *, unsigned char *,
   1744                          int, off_t);
   1745 void *create_session_info(int, unsigned char *, unsigned char *, int *);
   1746 void win_func(struct window *, struct links_event *, int);
   1747 void goto_url_f(struct session *, void (*)(struct session *), unsigned char *,
   1748                 unsigned char *, struct f_data_c *, int, int, int, int);
   1749 void goto_url(void *, unsigned char *);
   1750 void goto_url_utf8(struct session *, unsigned char *);
   1751 void goto_url_not_from_dialog(struct session *, unsigned char *,
   1752                               struct f_data_c *);
   1753 void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url,
   1754                  unsigned char *href, unsigned char *target);
   1755 void map_selected(struct terminal *term, void *ld, void *ses_);
   1756 void go_back(struct session *, int);
   1757 void go_backwards(struct terminal *term, void *psteps, void *ses_);
   1758 void reload(struct session *, int);
   1759 void cleanup_session(struct session *);
   1760 void destroy_session(struct session *);
   1761 struct f_data_c *find_frame(struct session *ses, unsigned char *target,
   1762                             struct f_data_c *base);
   1763 
   1764 /* Information about the current document */
   1765 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
   1766 unsigned char *get_current_title(struct f_data_c *, unsigned char *, size_t);
   1767 
   1768 unsigned char *get_form_url(struct session *ses, struct f_data_c *f,
   1769                             struct form_control *form, int *onsubmit);
   1770 
   1771 /* bfu.c */
   1772 
   1773 extern struct style *bfu_style_wb, *bfu_style_bw, *bfu_style_wb_b,
   1774     *bfu_style_bw_u, *bfu_style_bw_mono, *bfu_style_wb_mono,
   1775     *bfu_style_wb_mono_u;
   1776 extern long bfu_bg_color, bfu_fg_color;
   1777 
   1778 struct memory_list {
   1779 	size_t n;
   1780 	void *p[1];
   1781 };
   1782 
   1783 struct memory_list *getml(void *, ...);
   1784 void add_to_ml(struct memory_list **, ...);
   1785 void freeml(struct memory_list *);
   1786 
   1787 #define DIALOG_LB (DIALOG_LEFT_BORDER + DIALOG_LEFT_INNER_BORDER + 1)
   1788 #define DIALOG_TB (DIALOG_TOP_BORDER + DIALOG_TOP_INNER_BORDER + 1)
   1789 
   1790 extern unsigned char m_bar;
   1791 
   1792 #define M_BAR (&m_bar)
   1793 
   1794 struct menu_item {
   1795 	unsigned char *text;
   1796 	unsigned char *rtext;
   1797 	unsigned char *hotkey;
   1798 	void (*func)(struct terminal *, void *, void *);
   1799 	void *data;
   1800 	int in_m;
   1801 	int free_i;
   1802 };
   1803 
   1804 enum menu_items {
   1805 	MENU_FREE_ITEMS = 1,
   1806 	MENU_FREE_TEXT = 2,
   1807 	MENU_FREE_RTEXT = 4,
   1808 	MENU_FREE_HOTKEY = 8
   1809 };
   1810 
   1811 struct menu {
   1812 	int selected;
   1813 	int view;
   1814 	int nview;
   1815 	int xp, yp;
   1816 	int x, y, xw, yw;
   1817 	int ni;
   1818 	void *data;
   1819 	struct window *win;
   1820 	struct menu_item *items;
   1821 	void (*free_function)(void *);
   1822 	void *free_data;
   1823 	unsigned hotkeys[1];
   1824 };
   1825 
   1826 struct mainmenu {
   1827 	int selected;
   1828 	int sp;
   1829 	int ni;
   1830 	void *data;
   1831 	struct window *win;
   1832 	struct menu_item *items;
   1833 	unsigned hotkeys[1];
   1834 };
   1835 
   1836 struct history_item {
   1837 	list_entry_1st;
   1838 	unsigned char str[1];
   1839 };
   1840 
   1841 struct history {
   1842 	int n;
   1843 	struct list_head items;
   1844 };
   1845 
   1846 #define free_history(h) free_list(struct history_item, (h).items)
   1847 
   1848 enum dlog { D_END, D_CHECKBOX, D_FIELD, D_FIELD_PASS, D_BUTTON };
   1849 
   1850 enum bfu { B_ENTER = 1, B_ESC };
   1851 
   1852 struct dialog_item_data;
   1853 
   1854 typedef void (*msg_button_fn)(void *);
   1855 typedef void (*input_field_button_fn)(void *, unsigned char *);
   1856 
   1857 struct dialog_item {
   1858 	int type;
   1859 	int gid, gnum;            /* for buttons: gid - flags B_XXX */
   1860 	/* for fields: min/max */ /* for box: gid is box height */
   1861 	int (*fn)(struct dialog_data *, struct dialog_item_data *);
   1862 	struct history *history;
   1863 	int dlen;
   1864 	unsigned char *data;
   1865 	void *udata; /* for box: holds list */
   1866 	union {
   1867 		msg_button_fn msg_fn;
   1868 		input_field_button_fn input_fn;
   1869 	} u;
   1870 	unsigned char *text;
   1871 };
   1872 
   1873 struct dialog_item_data {
   1874 	int x, y, l;
   1875 	int vpos, cpos;
   1876 	int checked;
   1877 	struct dialog_item *item;
   1878 	struct list_head history;
   1879 	struct list_head *cur_hist;
   1880 	unsigned char *cdata;
   1881 };
   1882 
   1883 enum even { EVENT_PROCESSED, EVENT_NOT_PROCESSED };
   1884 
   1885 struct dialog {
   1886 	unsigned char *title;
   1887 	void (*fn)(struct dialog_data *);
   1888 	int (*handle_event)(struct dialog_data *, struct links_event *);
   1889 	void (*abort)(struct dialog_data *);
   1890 	void *udata;
   1891 	void *udata2;
   1892 	int align;
   1893 	void (*refresh)(void *);
   1894 	void *refresh_data;
   1895 	struct dialog_item items[1];
   1896 };
   1897 
   1898 struct dialog_data {
   1899 	struct window *win;
   1900 	struct dialog *dlg;
   1901 	int x, y, xw, yw;
   1902 	int n;
   1903 	int selected;
   1904 	struct memory_list *ml;
   1905 	int brl_y;
   1906 	struct dialog_item_data items[1];
   1907 };
   1908 
   1909 struct menu_item *new_menu(int);
   1910 void add_to_menu(struct menu_item **, unsigned char *, unsigned char *,
   1911                  unsigned char *, void (*)(struct terminal *, void *, void *),
   1912                  void *, int, int);
   1913 void do_menu(struct terminal *, struct menu_item *, void *);
   1914 void do_menu_selected(struct terminal *, struct menu_item *, void *, int,
   1915                       void (*)(void *), void *);
   1916 void do_mainmenu(struct terminal *, struct menu_item *, void *, int);
   1917 void do_dialog(struct terminal *, struct dialog *, struct memory_list *);
   1918 void dialog_func(struct window *, struct links_event *, int);
   1919 int check_number(struct dialog_data *, struct dialog_item_data *);
   1920 int check_hex_number(struct dialog_data *, struct dialog_item_data *);
   1921 int check_float(struct dialog_data *, struct dialog_item_data *);
   1922 int check_nonempty(struct dialog_data *, struct dialog_item_data *);
   1923 int check_local_ip_address(struct dialog_data *, struct dialog_item_data *);
   1924 int check_local_ipv6_address(struct dialog_data *, struct dialog_item_data *);
   1925 void max_text_width(struct terminal *, unsigned char *, int *, int);
   1926 void min_text_width(struct terminal *, unsigned char *, int *, int);
   1927 int dlg_format_text(struct dialog_data *, struct terminal *, unsigned char *,
   1928                     int, int *, int, int *, unsigned char, int);
   1929 void dlg_format_text_and_field(struct dialog_data *, struct terminal *,
   1930                                unsigned char *, struct dialog_item_data *, int,
   1931                                int *, int, int *, unsigned char, int);
   1932 void max_buttons_width(struct terminal *, struct dialog_item_data *, int,
   1933                        int *);
   1934 void min_buttons_width(struct terminal *, struct dialog_item_data *, int,
   1935                        int *);
   1936 void dlg_format_buttons(struct dialog_data *, struct terminal *,
   1937                         struct dialog_item_data *, int, int, int *, int, int *,
   1938                         int);
   1939 void checkboxes_width(struct terminal *, unsigned char *const *, int, int *,
   1940                       void (*)(struct terminal *, unsigned char *, int *, int));
   1941 void dlg_format_checkbox(struct dialog_data *, struct terminal *,
   1942                          struct dialog_item_data *, int, int *, int, int *,
   1943                          unsigned char *);
   1944 void dlg_format_checkboxes(struct dialog_data *, struct terminal *,
   1945                            struct dialog_item_data *, int, int, int *, int,
   1946                            int *, unsigned char *const *);
   1947 void dlg_format_field(struct dialog_data *, struct terminal *,
   1948                       struct dialog_item_data *, int, int *, int, int *, int);
   1949 void max_group_width(struct terminal *, unsigned char *const *,
   1950                      struct dialog_item_data *, int, int *);
   1951 void min_group_width(struct terminal *, unsigned char *const *,
   1952                      struct dialog_item_data *, int, int *);
   1953 void dlg_format_group(struct dialog_data *, struct terminal *,
   1954                       unsigned char *const *, struct dialog_item_data *, int,
   1955                       int, int *, int, int *);
   1956 /*void dlg_format_box(struct terminal *, struct terminal *, struct
   1957  * dialog_item_data *, int, int *, int, int *, int);*/
   1958 void checkbox_list_fn(struct dialog_data *);
   1959 void group_fn(struct dialog_data *);
   1960 void center_dlg(struct dialog_data *);
   1961 void draw_dlg(struct dialog_data *);
   1962 void display_dlg_item(struct dialog_data *, struct dialog_item_data *, int);
   1963 int check_dialog(struct dialog_data *);
   1964 void get_dialog_data(struct dialog_data *);
   1965 int ok_dialog(struct dialog_data *, struct dialog_item_data *);
   1966 int cancel_dialog(struct dialog_data *, struct dialog_item_data *);
   1967 
   1968 void msg_box_fn(struct dialog_data *dlg);
   1969 void msg_box_null(void *);
   1970 #define MSG_BOX_END ((unsigned char *)NULL)
   1971 void msg_box(struct terminal *, struct memory_list *, unsigned char *, int,
   1972              /*unsigned char *, void *, int,*/...);
   1973 /* msg_box arguments:
   1974  *		terminal,
   1975  *		blocks to free,
   1976  *		title,
   1977  *		alignment,
   1978  *		strings (followed by MSG_BOX_END),
   1979  *		data for function,
   1980  *		number of buttons,
   1981  *		button title, function, hotkey,
   1982  *		... other buttons
   1983  */
   1984 
   1985 void input_field_null(void);
   1986 void input_field(struct terminal *, struct memory_list *, unsigned char *,
   1987                  unsigned char *, void *, struct history *, int,
   1988                  unsigned char *, int, int,
   1989                  int (*)(struct dialog_data *, struct dialog_item_data *),
   1990                  int n, ...);
   1991 /* input_field arguments:
   1992  *		terminal,
   1993  *		blocks to free,
   1994  *		title,
   1995  *		question,
   1996  *		data for functions,
   1997  *		history,
   1998  *		length,
   1999  *		string to fill the dialog with,
   2000  *		minimal value,
   2001  *		maximal value,
   2002  *		check_function,
   2003  *		the number of buttons,
   2004  *		OK button text,
   2005  *		ok function,
   2006  *		CANCEL button text,
   2007  *		cancel function,
   2008  *
   2009  *	field can have multiple buttons and functions, and finally NULL
   2010  *	(warning: if there's no cancel function, there will be two NULLs in
   2011  *	a call). Functions have type
   2012  *	void (*fn)(void *data, unsigned char *text), only the last one has type
   2013  *	void (*fn)(void *data). Check it carefully because the compiler wont!
   2014  */
   2015 void add_to_history(struct terminal *, struct history *, unsigned char *);
   2016 
   2017 int find_msg_box(struct terminal *term, unsigned char *title,
   2018                  int (*sel)(void *, void *), void *data);
   2019 
   2020 /* menu.c */
   2021 
   2022 extern struct history goto_url_history;
   2023 
   2024 void activate_keys(struct session *ses);
   2025 void reset_settings_for_tor(void);
   2026 int save_proxy(int charset, unsigned char *result, unsigned char *proxy);
   2027 int save_noproxy_list(int charset, unsigned char *result,
   2028                       unsigned char *noproxy_list);
   2029 void dialog_html_options(struct session *ses);
   2030 void activate_bfu_technology(struct session *, int);
   2031 void dialog_goto_url(struct session *ses, unsigned char *url);
   2032 void dialog_save_url(struct session *ses);
   2033 void free_history_lists(void);
   2034 void query_file(struct session *, unsigned char *, unsigned char *,
   2035                 void (*)(struct session *, unsigned char *, int),
   2036                 void (*)(void *), int);
   2037 #define DOWNLOAD_DEFAULT   0
   2038 #define DOWNLOAD_OVERWRITE 1
   2039 #define DOWNLOAD_CONTINUE  2
   2040 void search_dlg(struct session *, struct f_data_c *, int);
   2041 void search_back_dlg(struct session *, struct f_data_c *, int);
   2042 void exit_prog(struct terminal *, void *, void *);
   2043 void really_exit_prog(void *ses_);
   2044 void query_exit(struct session *ses);
   2045 
   2046 /* charsets.c */
   2047 
   2048 struct conv_table {
   2049 	int t;
   2050 	union {
   2051 		unsigned char *str;
   2052 		struct conv_table *tbl;
   2053 	} u;
   2054 };
   2055 
   2056 struct conv_table *get_translation_table(const int, const int);
   2057 
   2058 #define is_entity_terminator(c)                                                \
   2059 	(c <= ' ' || c == ';' || c == '&' || c == '/' || c == '?')
   2060 
   2061 unsigned int locase(unsigned int a);
   2062 unsigned int upcase(unsigned int a);
   2063 int get_entity_number(unsigned char *st, int l);
   2064 unsigned char *get_entity_string(unsigned char *, int);
   2065 unsigned char *convert_string(struct conv_table *, unsigned char *, int,
   2066                               struct document_options *);
   2067 unsigned char *convert(int from, int to, unsigned char *c,
   2068                        struct document_options *dopt);
   2069 unsigned char *get_cp_name(int);
   2070 unsigned char *get_cp_mime_name(int);
   2071 unsigned char *encode_utf_8(int);
   2072 unsigned char *u2cp(int u);
   2073 
   2074 unsigned uni_locase(unsigned);
   2075 unsigned charset_upcase(unsigned, int);
   2076 void charset_upcase_string(unsigned char **, int);
   2077 unsigned char *unicode_upcase_string(unsigned char *ch);
   2078 unsigned char *to_utf8_upcase(unsigned char *str, int cp);
   2079 int compare_case_utf8(unsigned char *u1, unsigned char *u2);
   2080 
   2081 unsigned get_utf_8(unsigned char **p);
   2082 #define GET_UTF_8(s, c)                                                        \
   2083 	do {                                                                   \
   2084 		if ((unsigned char)(s)[0] < 0x80)                              \
   2085 			(c) = (s)++[0];                                        \
   2086 		else if ((unsigned char)(s)[0] >= 0xc2                         \
   2087 		         && (unsigned char)(s)[0] < 0xe0                       \
   2088 		         && ((unsigned char)(s)[1] & 0xc0) == 0x80) {          \
   2089 			(c) = (unsigned char)(s)[0] * 0x40                     \
   2090 			      + (unsigned char)(s)[1],                         \
   2091 			(c) -= 0x3080, (s) += 2;                               \
   2092 		} else                                                         \
   2093 			(c) = get_utf_8(&(s));                                 \
   2094 	} while (0)
   2095 #define FWD_UTF_8(s)                                                           \
   2096 	do {                                                                   \
   2097 		if ((unsigned char)(s)[0] < 0x80)                              \
   2098 			(s)++;                                                 \
   2099 		else                                                           \
   2100 			get_utf_8(&(s));                                       \
   2101 	} while (0)
   2102 #define BACK_UTF_8(p, b)                                                       \
   2103 	do {                                                                   \
   2104 		while ((p) > (b)) {                                            \
   2105 			(p)--;                                                 \
   2106 			if ((*(p)&0xc0) != 0x80)                               \
   2107 				break;                                         \
   2108 		}                                                              \
   2109 	} while (0)
   2110 
   2111 extern unsigned char utf_8_1[256];
   2112 
   2113 static inline int
   2114 utf8chrlen(unsigned char c)
   2115 {
   2116 	unsigned char l = utf_8_1[c];
   2117 	if (l == 7)
   2118 		return 1;
   2119 	return 7 - l;
   2120 }
   2121 
   2122 static inline unsigned
   2123 GET_TERM_CHAR(struct terminal *term, unsigned char **str)
   2124 {
   2125 	unsigned ch;
   2126 	GET_UTF_8(*str, ch);
   2127 	return ch;
   2128 }
   2129 
   2130 /* view.c */
   2131 
   2132 unsigned char *textptr_add(unsigned char *t, int i, int cp);
   2133 int textptr_diff(unsigned char *t2, unsigned char *t1, int cp);
   2134 
   2135 extern int ismap_link, ismap_x, ismap_y;
   2136 
   2137 void frm_download(struct session *, struct f_data_c *);
   2138 void frm_download_image(struct session *, struct f_data_c *);
   2139 void frm_view_image(struct session *, struct f_data_c *);
   2140 struct format_text_cache_entry *format_text(struct f_data_c *fd,
   2141                                             struct form_control *fc,
   2142                                             struct form_state *fs);
   2143 int area_cursor(struct f_data_c *f, struct form_control *fc,
   2144                 struct form_state *fs);
   2145 struct form_state *find_form_state(struct f_data_c *, struct form_control *);
   2146 void fixup_select_state(struct form_control *fc, struct form_state *fs);
   2147 int enter(struct session *ses, struct f_data_c *f, int a);
   2148 int field_op(struct session *ses, struct f_data_c *f, struct link *l,
   2149              struct links_event *ev);
   2150 
   2151 int can_open_in_new(struct terminal *);
   2152 void open_in_new_window(struct terminal *, void *fn_, void *ses_);
   2153 extern void (*const send_open_new_xterm_ptr)(struct terminal *, void *fn_,
   2154                                              void *ses_);
   2155 void destroy_fc(struct form_control *);
   2156 void sort_links(struct f_data *);
   2157 struct view_state *create_vs(void);
   2158 void destroy_vs(struct view_state *);
   2159 int dump_to_file(struct f_data *, int);
   2160 void check_vs(struct f_data_c *);
   2161 void draw_doc(struct terminal *t, void *scr_);
   2162 void draw_formatted(struct session *);
   2163 void draw_fd(struct f_data_c *);
   2164 void next_frame(struct session *, int);
   2165 void send_event(struct session *, struct links_event *);
   2166 void link_menu(struct terminal *, void *, void *);
   2167 void save_as(struct terminal *, void *, void *);
   2168 void save_url(void *, unsigned char *);
   2169 void menu_save_formatted(struct terminal *, void *, void *);
   2170 void copy_url_location(struct terminal *, void *, void *);
   2171 void selected_item(struct terminal *, void *, void *);
   2172 void toggle(struct session *, struct f_data_c *, int);
   2173 void do_for_frame(struct session *,
   2174                   void (*)(struct session *, struct f_data_c *, int), int);
   2175 int get_current_state(struct session *);
   2176 unsigned char *print_current_link(struct session *);
   2177 unsigned char *print_current_title(struct session *);
   2178 void loc_msg(struct terminal *, struct location *, struct f_data_c *);
   2179 void state_msg(struct session *);
   2180 void head_msg(struct session *);
   2181 void search_for(void *, unsigned char *);
   2182 void search_for_back(void *, unsigned char *);
   2183 void find_next(struct session *, struct f_data_c *, int);
   2184 void find_next_back(struct session *, struct f_data_c *, int);
   2185 void set_frame(struct session *, struct f_data_c *, int);
   2186 struct f_data_c *current_frame(struct session *);
   2187 void reset_form(struct f_data_c *f, int form_num);
   2188 void set_textarea(struct session *, struct f_data_c *, int);
   2189 
   2190 /* html.c */
   2191 
   2192 enum html_attr {
   2193 	AT_BOLD = 1,
   2194 	AT_ITALIC = 2,
   2195 	AT_UNDERLINE = 4,
   2196 	AT_FIXED = 8,
   2197 	AT_GRAPHICS = 16,
   2198 	AT_INVERT = 32
   2199 };
   2200 
   2201 enum html_al {
   2202 	AL_LEFT,
   2203 	AL_CENTER,
   2204 	AL_RIGHT,
   2205 	AL_BLOCK,
   2206 	AL_NO,
   2207 	AL_NO_BREAKABLE,
   2208 	AL_BOTTOM,
   2209 	AL_MIDDLE,
   2210 	AL_TOP,
   2211 
   2212 	AL_MASK,
   2213 	AL_NOBRLEXP,
   2214 	AL_MONO
   2215 };
   2216 
   2217 struct text_attrib_beginning {
   2218 	int attr;
   2219 	struct rgb fg;
   2220 	struct rgb bg;
   2221 	int fontsize;
   2222 	int baseline;
   2223 };
   2224 
   2225 struct text_attrib {
   2226 	int attr;
   2227 	struct rgb fg;
   2228 	struct rgb bg;
   2229 	int fontsize;
   2230 	int baseline;
   2231 	unsigned char *fontface;
   2232 	unsigned char *link;
   2233 	unsigned char *target;
   2234 	unsigned char *image;
   2235 	struct form_control *form;
   2236 	struct rgb clink;
   2237 	unsigned char *href_base;
   2238 	unsigned char *target_base;
   2239 	unsigned char *select;
   2240 	int select_disabled;
   2241 };
   2242 
   2243 enum par_t { P_NUMBER = 1, P_alpha, P_ALPHA, P_roman, P_ROMAN };
   2244 
   2245 enum par_s { P_STAR = 1, P_O, P_PLUS, P_LISTMASK = 7, P_COMPACT };
   2246 
   2247 struct par_attrib {
   2248 	int align;
   2249 	int leftmargin;
   2250 	int rightmargin;
   2251 	int width;
   2252 	int list_level;
   2253 	unsigned list_number;
   2254 	int dd_margin;
   2255 	int flags;
   2256 	struct rgb bgcolor;
   2257 	int implicit_pre_wrap;
   2258 };
   2259 
   2260 struct html_element {
   2261 	list_entry_1st;
   2262 	struct text_attrib attr;
   2263 	struct par_attrib parattr;
   2264 #define INVISIBLE        1
   2265 #define INVISIBLE_SCRIPT 2
   2266 #define INVISIBLE_STYLE  3
   2267 	int invisible;
   2268 	unsigned char *name;
   2269 	int namelen;
   2270 	unsigned char *options;
   2271 	int linebreak;
   2272 	int dontkill;
   2273 	struct frameset_desc *frameset;
   2274 };
   2275 
   2276 extern int get_attr_val_nl;
   2277 
   2278 extern struct list_head html_stack;
   2279 extern int line_breax;
   2280 
   2281 extern int html_format_changed;
   2282 
   2283 extern unsigned char *startf;
   2284 extern unsigned char *eofff;
   2285 
   2286 #define html_top_  list_struct(html_stack.next, struct html_element)
   2287 #define html_top   (*html_top_)
   2288 #define format_    (html_top.attr)
   2289 #define par_format (html_top.parattr)
   2290 
   2291 extern void *ff;
   2292 extern void (*put_chars_f)(void *, unsigned char *, int);
   2293 extern void (*line_break_f)(void *);
   2294 extern void *(*special_f)(void *, int, ...);
   2295 
   2296 extern int table_level;
   2297 extern int empty_format;
   2298 
   2299 extern struct form form;
   2300 extern unsigned char *last_form_tag;
   2301 extern unsigned char *last_form_attr;
   2302 extern unsigned char *last_input_tag;
   2303 
   2304 extern unsigned char *last_link;
   2305 extern unsigned char *last_image;
   2306 extern unsigned char *last_target;
   2307 extern struct form_control *last_form;
   2308 
   2309 int parse_element(unsigned char *, unsigned char *, unsigned char **, int *,
   2310                   unsigned char **, unsigned char **);
   2311 unsigned char *get_attr_val(unsigned char *, unsigned char *);
   2312 int has_attr(unsigned char *, unsigned char *);
   2313 int get_num(unsigned char *, unsigned char *);
   2314 int get_width(unsigned char *, unsigned char *, int);
   2315 int get_color(unsigned char *, unsigned char *, struct rgb *);
   2316 int get_bgcolor(unsigned char *, struct rgb *);
   2317 void html_stack_dup(void);
   2318 void kill_html_stack_item(struct html_element *);
   2319 int should_skip_script(unsigned char *);
   2320 unsigned char *skip_comment(unsigned char *, unsigned char *);
   2321 void parse_html(unsigned char *, unsigned char *,
   2322                 void (*)(void *, unsigned char *, int), void (*)(void *),
   2323                 void *(*)(void *, int, ...), void *, unsigned char *);
   2324 int get_image_map(unsigned char *, unsigned char *, unsigned char *,
   2325                   unsigned char *a, struct menu_item **, struct memory_list **,
   2326                   unsigned char *, unsigned char *, int, int, int, int gfx);
   2327 size_t scan_http_equiv(unsigned char *, unsigned char *, unsigned char **,
   2328                        size_t, unsigned char **, unsigned char **,
   2329                        unsigned char **, int *);
   2330 
   2331 int decode_color(unsigned char *, struct rgb *);
   2332 
   2333 enum sp {
   2334 	SP_TAG,
   2335 	SP_CONTROL,
   2336 	SP_TABLE,
   2337 	SP_USED,
   2338 	SP_FRAMESET,
   2339 	SP_FRAME,
   2340 	SP_SCRIPT,
   2341 	SP_IMAGE,
   2342 	SP_NOWRAP,
   2343 	SP_REFRESH,
   2344 	SP_SET_BASE,
   2345 	SP_HR
   2346 };
   2347 
   2348 struct frameset_param {
   2349 	struct frameset_desc *parent;
   2350 	int x, y;
   2351 	int *xw, *yw;
   2352 };
   2353 
   2354 enum scroll { SCROLLING_NO, SCROLLING_YES, SCROLLING_AUTO };
   2355 
   2356 struct frame_param {
   2357 	struct frameset_desc *parent;
   2358 	unsigned char *name;
   2359 	unsigned char *url;
   2360 	int marginwidth;
   2361 	int marginheight;
   2362 	unsigned char scrolling;
   2363 };
   2364 
   2365 struct refresh_param {
   2366 	unsigned char *url;
   2367 	int time;
   2368 };
   2369 
   2370 struct hr_param {
   2371 	int size;
   2372 	int width;
   2373 };
   2374 
   2375 void free_menu(struct menu_item *);
   2376 void do_select_submenu(struct terminal *, void *, void *);
   2377 
   2378 void clr_white(unsigned char *name);
   2379 void clr_spaces(unsigned char *name, int firstlast);
   2380 
   2381 /* html_r.c */
   2382 
   2383 extern int g_ctrl_num;
   2384 
   2385 extern struct conv_table *convert_table;
   2386 
   2387 struct part {
   2388 	int x, y;
   2389 	int xp, yp;
   2390 	int xmax;
   2391 	int xa;
   2392 	int cx, cy;
   2393 	struct f_data *data;
   2394 	int attribute;
   2395 	unsigned char *spaces;
   2396 	int z_spaces;
   2397 	int spl;
   2398 	int link_num;
   2399 	struct list_head uf;
   2400 	unsigned char utf8_part[7];
   2401 	unsigned char utf8_part_len;
   2402 };
   2403 
   2404 struct sizes {
   2405 	int xmin, xmax, y;
   2406 };
   2407 
   2408 extern struct f_data *current_f_data;
   2409 
   2410 void free_additional_files(struct additional_files **);
   2411 void free_frameset_desc(struct frameset_desc *);
   2412 struct frameset_desc *copy_frameset_desc(struct frameset_desc *);
   2413 
   2414 struct f_data *init_formatted(struct document_options *);
   2415 void destroy_formatted(struct f_data *);
   2416 
   2417 /* d_opt je podle Mikulase nedefinovany mimo html parser, tak to jinde
   2418  * nepouzivejte
   2419  *
   2420  * -- Brain
   2421  */
   2422 extern struct document_options dd_opt;
   2423 extern struct document_options *d_opt;
   2424 extern int margin;
   2425 
   2426 int find_nearest_color(struct rgb *r, int l);
   2427 int fg_color(int fg, int bg);
   2428 
   2429 void xxpand_line(struct part *, int, int);
   2430 void xxpand_lines(struct part *, int);
   2431 void xset_hchar(struct part *, int, int, unsigned, unsigned char);
   2432 void xset_hchars(struct part *, int, int, int, unsigned, unsigned char);
   2433 void html_tag(struct f_data *, unsigned char *, int, int);
   2434 void process_script(struct f_data *, unsigned char *);
   2435 void set_base(struct f_data *, unsigned char *);
   2436 void html_process_refresh(struct f_data *, unsigned char *, int);
   2437 
   2438 int compare_opt(struct document_options *, struct document_options *);
   2439 void copy_opt(struct document_options *, struct document_options *);
   2440 
   2441 struct link *new_link(struct f_data *);
   2442 struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *,
   2443                                      int);
   2444 struct part *format_html_part(unsigned char *, unsigned char *, int, int, int,
   2445                               struct f_data *, int, int, unsigned char *, int);
   2446 void really_format_html(struct cache_entry *, unsigned char *, unsigned char *,
   2447                         struct f_data *, int frame);
   2448 struct link *get_link_at_location(struct f_data *f, int x, int y);
   2449 int get_search_data(struct f_data *);
   2450 
   2451 struct frameset_desc *create_frameset(struct f_data *fda,
   2452                                       struct frameset_param *fp);
   2453 void create_frame(struct frame_param *fp);
   2454 
   2455 /* html_tbl.c */
   2456 
   2457 unsigned char *skip_element(unsigned char *, unsigned char *, unsigned char *,
   2458                             int);
   2459 void format_table(unsigned char *, unsigned char *, unsigned char *,
   2460                   unsigned char **, void *);
   2461 void table_bg(struct text_attrib *ta, unsigned char bgstr[8]);
   2462 
   2463 void *find_table_cache_entry(unsigned char *start, unsigned char *end,
   2464                              int align, int m, int width, int xs, int link_num);
   2465 void add_table_cache_entry(unsigned char *start, unsigned char *end, int align,
   2466                            int m, int width, int xs, int link_num, void *p);
   2467 
   2468 /* default.c */
   2469 
   2470 extern unsigned char default_target[MAX_STR_LEN];
   2471 
   2472 unsigned char *parse_options(int, char *[]);
   2473 void init_home(void);
   2474 unsigned char *read_config_file(unsigned char *);
   2475 int write_to_config_file(unsigned char *, unsigned char *, int);
   2476 void load_config(void);
   2477 void write_config(struct terminal *);
   2478 void write_html_config(struct terminal *);
   2479 void end_config(void);
   2480 
   2481 void load_url_history(void);
   2482 void save_url_history(void);
   2483 
   2484 struct driver_param {
   2485 	list_entry_1st;
   2486 	int kbd_codepage;
   2487 	int palette_mode;
   2488 	unsigned char *param;
   2489 	unsigned char shell_term[MAX_STR_LEN];
   2490 	int nosave;
   2491 	unsigned char name[1];
   2492 };
   2493 /* -if exec is NULL, shell_term is unused
   2494    -otherwise this string describes shell to be executed by the
   2495     exec function, the '%' char means string to be executed
   2496    -shell cannot be NULL
   2497    -if exec is !NULL and shell is empty, exec should use some
   2498     default shell (e.g. "xterm -e %")
   2499 */
   2500 
   2501 struct driver_param *get_driver_param(unsigned char *);
   2502 
   2503 extern int anonymous;
   2504 
   2505 extern unsigned char system_name[];
   2506 
   2507 extern unsigned char *links_home;
   2508 extern int first_use;
   2509 
   2510 extern int disable_libevent;
   2511 extern int no_connect;
   2512 extern int base_session;
   2513 #define D_DUMP   1
   2514 #define D_SOURCE 2
   2515 extern int dmp;
   2516 extern int screen_width;
   2517 extern int dump_codepage;
   2518 extern int force_html;
   2519 
   2520 extern int max_connections;
   2521 extern int max_connections_to_host;
   2522 extern int max_tries;
   2523 extern int receive_timeout;
   2524 extern int unrestartable_receive_timeout;
   2525 extern int timeout_multiple_addresses;
   2526 extern unsigned char bind_ip_address[16];
   2527 extern unsigned char bind_ipv6_address[INET6_ADDRSTRLEN];
   2528 extern int download_utime;
   2529 
   2530 extern int max_format_cache_entries;
   2531 extern int memory_cache_size;
   2532 extern int image_cache_size;
   2533 extern int font_cache_size;
   2534 extern int aggressive_cache;
   2535 
   2536 struct ipv6_options {
   2537 	int addr_preference;
   2538 };
   2539 
   2540 enum addr {
   2541 	ADDR_PREFERENCE_DEFAULT,
   2542 	ADDR_PREFERENCE_IPV4,
   2543 	ADDR_PREFERENCE_IPV6,
   2544 	ADDR_PREFERENCE_IPV4_ONLY,
   2545 	ADDR_PREFERENCE_IPV6_ONLY
   2546 };
   2547 
   2548 extern struct ipv6_options ipv6_options;
   2549 
   2550 struct proxies {
   2551 	unsigned char http_proxy[MAX_STR_LEN];
   2552 	unsigned char https_proxy[MAX_STR_LEN];
   2553 	unsigned char socks_proxy[MAX_STR_LEN];
   2554 	unsigned char dns_append[MAX_STR_LEN];
   2555 	unsigned char no_proxy[MAX_STR_LEN];
   2556 	int only_proxies;
   2557 };
   2558 
   2559 extern struct proxies proxies;
   2560 
   2561 enum ssl_cert {
   2562 	SSL_ACCEPT_INVALID_CERTIFICATE,
   2563 	SSL_WARN_ON_INVALID_CERTIFICATE,
   2564 	SSL_REJECT_INVALID_CERTIFICATE
   2565 };
   2566 
   2567 struct ssl_options {
   2568 	int certificates;
   2569 	int built_in_certificates;
   2570 	unsigned char client_cert_key[MAX_STR_LEN];
   2571 	unsigned char client_cert_crt[MAX_STR_LEN];
   2572 	unsigned char client_cert_password[MAX_STR_LEN];
   2573 };
   2574 
   2575 extern struct ssl_options ssl_options;
   2576 
   2577 struct http_header_options {
   2578 	int fake_firefox;
   2579 	unsigned char fake_useragent[MAX_STR_LEN];
   2580 	unsigned char extra_header[MAX_STR_LEN];
   2581 };
   2582 
   2583 struct http_options {
   2584 	int http10;
   2585 	int allow_blacklist;
   2586 	int no_accept_charset;
   2587 	int no_compression;
   2588 	int retry_internal_errors;
   2589 	struct http_header_options header;
   2590 };
   2591 
   2592 extern struct http_options http_options;
   2593 
   2594 extern unsigned char download_dir[];
   2595 
   2596 #define SCRUB_HEADERS (proxies.only_proxies || http_options.header.fake_firefox)
   2597 
   2598 extern double display_red_gamma, display_green_gamma, display_blue_gamma;
   2599 extern double user_gamma;
   2600 extern double bfu_aspect;
   2601 extern int dither_letters;
   2602 extern int dither_images;
   2603 extern int gamma_bits;
   2604 extern int overwrite_instead_of_scroll;
   2605 
   2606 extern unsigned char bookmarks_file[MAX_STR_LEN];
   2607 
   2608 extern int save_history;
   2609 
   2610 extern struct document_setup dds;
   2611 
   2612 /* listedit.c */
   2613 
   2614 enum title { TITLE_EDIT, TITLE_ADD };
   2615 
   2616 struct list {
   2617 	list_entry_1st;
   2618 	unsigned char type;
   2619 	/*
   2620 	 * bit 0: 0=item, 1=directory
   2621 	 * bit 1: directory is open (1)/closed (0); for item unused
   2622 	 * bit 2: 1=item is selected 0=item is not selected
   2623 	 */
   2624 	int depth;
   2625 	struct list *fotr; /* ignored when list is flat */
   2626 };
   2627 
   2628 #define list_next(l) (list_struct((l)->list_entry.next, struct list))
   2629 #define list_prev(l) (list_struct((l)->list_entry.prev, struct list))
   2630 
   2631 #define list_head_1st struct list head;
   2632 #define list_head_last
   2633 
   2634 struct list_description {
   2635 	unsigned char type; /* 0=flat, 1=tree */
   2636 	struct list *list;  /* head of the list */
   2637 	struct list *(*new_item)(
   2638 	    void * /* data in internal format */); /* creates new item, does NOT
   2639 	                                              add to the list */
   2640 	void (*edit_item)(struct dialog_data *, struct list *,
   2641 	                  void (*)(struct dialog_data *, struct list *,
   2642 	                           struct list *,
   2643 	                           struct list_description *) /* ok function */,
   2644 	                  struct list * /* parameter for the ok_function */,
   2645 	                  unsigned char); /* must call call delete_item on the
   2646 	                                     item after all */
   2647 	void *(*default_value)(
   2648 	    struct session *,
   2649 	    unsigned char /* 0=item, 1=directory */); /* called when add button
   2650 	                                                 is pressed, allocates
   2651 	                                                 memory, return value is
   2652 	                                                 passed to the new_item
   2653 	                                                 function, new_item
   2654 	                                                 fills the item with
   2655 	                                                 this data */
   2656 	void (*delete_item)(
   2657 	    struct list *); /* delete item, if next and prev are not NULL
   2658 	                       adjusts pointers in the list */
   2659 	void (*copy_item)(
   2660 	    struct list * /* old */,
   2661 	    struct list
   2662 		* /* new */); /* gets 2 allocated items, copies all item data
   2663 	                         except pointers from first item to second one,
   2664 	                         old data (in second item) will be destroyed */
   2665 	unsigned char *(*type_item)(struct terminal *, struct list *, int /* 0=type whole item (e.g. when deleting item), 1=type only e.g title (in list window )*/);   /* alllocates buffer and writes item into it */
   2666 	struct list *(*find_item)(
   2667 	    struct list *start_item, unsigned char *string,
   2668 	    int direction /* 1 or -1 */); /* returns pointer to the first item
   2669 	                                     matching given string or NULL if
   2670 	                                     failed. Search starts at start_item
   2671 	                                     including. */
   2672 	struct history *search_history;
   2673 	int codepage; /* codepage of all string */
   2674 	int n_items;  /* number of items in main window */
   2675 
   2676 	/* following items are string codes */
   2677 	int item_description;    /* e.g. "bookmark" or "extension" ... */
   2678 	int already_in_use;      /* e.g. "Bookmarks window is already open" */
   2679 	int window_title;        /* main window title */
   2680 	int delete_dialog_title; /* e.g. "Delete bookmark dialog" */
   2681 	int button;              /* when there's no button button_fn is NULL */
   2682 
   2683 	void (*button_fn)(struct session *,
   2684 	                  struct list *); /* gets pointer to the item */
   2685 	void (*save)(struct session *);
   2686 
   2687 	/* internal variables, should not be modified, initially set to 0 */
   2688 	struct list *current_pos;
   2689 	struct list *win_offset;
   2690 	int win_pos;
   2691 	int open;     /* 0=closed, 1=open */
   2692 	int modified; /* listedit reports 1 when the list was modified by user
   2693 	                 (and should be e.g. saved) */
   2694 	struct dialog_data *dlg; /* current dialog, valid only when open==1 */
   2695 	unsigned char *search_word;
   2696 	int search_direction;
   2697 };
   2698 
   2699 int test_list_window_in_use(struct list_description *ld, struct terminal *term);
   2700 int create_list_window(struct list_description *, struct list *,
   2701                        struct terminal *, struct session *);
   2702 void
   2703 reinit_list_window(struct list_description *ld); /* reinitializes list window */
   2704 
   2705 /* types.c */
   2706 
   2707 struct list;
   2708 
   2709 struct assoc {
   2710 	list_head_1st unsigned char *label;
   2711 	unsigned char *ct;
   2712 	unsigned char *prog;
   2713 	int cons;
   2714 	int xwin;
   2715 	int block;
   2716 	int ask;
   2717 	int accept_http;
   2718 	int accept_ftp;
   2719 	int system;
   2720 	list_head_last
   2721 };
   2722 
   2723 struct extension {
   2724 	list_head_1st unsigned char *ext;
   2725 	unsigned char *ct;
   2726 	list_head_last
   2727 };
   2728 
   2729 struct protocol_program {
   2730 	list_entry_1st;
   2731 	unsigned char *prog;
   2732 	int system;
   2733 };
   2734 
   2735 extern struct list assoc;
   2736 extern struct list extensions;
   2737 
   2738 unsigned char *get_compress_by_extension(char *, char *);
   2739 unsigned char *get_content_type_by_extension(unsigned char *url);
   2740 unsigned char *get_content_type(unsigned char *, unsigned char *);
   2741 unsigned char *get_content_encoding(unsigned char *head, unsigned char *url,
   2742                                     int just_ce);
   2743 unsigned char *encoding_2_extension(unsigned char *);
   2744 struct assoc *get_type_assoc(struct terminal *term, unsigned char *, int *);
   2745 int is_html_type(unsigned char *ct);
   2746 unsigned char *get_filename_from_header(unsigned char *head);
   2747 unsigned char *get_filename_from_url(unsigned char *, unsigned char *, int);
   2748 
   2749 void menu_assoc_manager(struct terminal *, void *, void *);
   2750 void update_assoc(struct assoc *);
   2751 void menu_ext_manager(struct terminal *, void *, void *);
   2752 void update_ext(struct extension *);
   2753 void update_prog(struct list_head *, unsigned char *, int);
   2754 unsigned char *get_prog(struct list_head *);
   2755 void create_initial_extensions(void);
   2756 
   2757 void free_types(void);
   2758 
   2759 /* bookmark.c */
   2760 
   2761 /* Where all bookmarks are kept */
   2762 extern struct list bookmarks;
   2763 
   2764 void finalize_bookmarks(void); /* called, when exiting links */
   2765 void init_bookmarks(void);     /* called at start */
   2766 void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file);
   2767 
   2768 /* Launches bookmark manager */
   2769 void menu_bookmark_manager(struct terminal *, void *, void *);