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 /*
8 * WARNING: this file MUST be C++ compatible. this means:
9 * no implicit conversions from void *:
10 * BAD: unsigned char *c = mem_alloc(4);
11 * GOOD: unsigned char *c = (unsigned char *)mem_alloc(4);
12 * no implicit char * -> unsigned char * conversions:
13 * BAD: unsigned char *c = stracpy("A");
14 * GOOD: unsigned char *c = stracpy((unsigned char *)"A");
15 * no implicit unsigned char * -> char * conversions:
16 * BAD: unsigned char *x, *y, *z; z = strcpy(x, y);
17 * BAD: l = strlen(x);
18 * GOOD: unsigned char *x, *y; z = (unsigned char *)strcpy((char *)x, (char *)y);
19 * GOOD: l = strlen((char *)x);
20 * don't use C++ keywords (like template)
21 * if there is struct X, you cannot use variable X or typedef X
22 * (this applies to typedef ip as well -- don't use it!)
23 *
24 * IF YOU WRITE ANYTHING NEW TO THIS FILE, try compiling this file in c++
25 * to make sure that you didn't break anything:
26 * g++ -DHAVE_CONFIG_H -x c++ links.h
27 */
28 #ifndef LINKS_H
29 #define LINKS_H
30
31 #include "cfg.h"
32
33 #include "com-defs.h"
34
35 #define LINKS_COPYRIGHT "(C) 1999 - 2021 Mikulas Patocka\n(C) 2000 - 2021 Petr Kulhavy, Karel Kulhavy, Martin Pergel"
36 #define LINKS_COPYRIGHT_8859_1 "(C) 1999 - 2021 Mikul\341s Patocka\n(C) 2000 - 2021 Petr Kulhav\375, Karel Kulhav\375, Martin Pergel"
37 #define LINKS_COPYRIGHT_8859_2 "(C) 1999 - 2021 Mikul\341\271 Pato\350ka\n(C) 2000 - 2021 Petr Kulhav\375, Karel Kulhav\375, Martin Pergel"
38
39 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
40 #if ((__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))) && \
41 !(defined(__clang__) || defined(__llvm__) || defined(__ICC) || defined(__OPEN64__) || defined(__PATHSCALE__) || defined(__PGI) || defined(__PGIC__)) && \
42 defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) && \
43 !(defined(__arm__) && defined(__thumb__) && !defined(__thumb2__)) /* avoid gcc bug */
44 #pragma GCC optimize ("-ftree-vectorize", "-ffast-math")
45 #endif
46 #endif
47
48 #include "os_dep.h"
49 #include <stdio.h>
50 #ifdef HAVE_STDLIB_H_X
51 #include <stdlib.h>
52 #endif
53 #include <stdarg.h>
54 #include <stddef.h>
55 #ifdef HAVE_UNISTD_H
56 #include <unistd.h>
57 #endif
58 #ifdef HAVE_STRING_H
59 #include <string.h>
60 #endif
61 #ifdef HAVE_BSD_STRING_H
62 #include <bsd/string.h>
63 #endif
64 #ifdef HAVE_STRINGS_H
65 #include <strings.h>
66 #endif
67 #include <errno.h>
68 #ifdef HAVE_LIMITS_H
69 #include <limits.h>
70 #endif
71 #include <sys/types.h>
72 #ifdef HAVE_INTTYPES_H
73 #include <inttypes.h>
74 #endif
75
76 #ifndef __USE_XOPEN
77 #define U_X
78 #define __USE_XOPEN
79 #endif
80 #ifndef _XOPEN_SOURCE
81 #define X_S
82 #define _XOPEN_SOURCE 5 /* The 5 is a kludge to get a strptime() prototype in NetBSD */
83 #endif
84 #ifdef TIME_WITH_SYS_TIME
85 #ifdef HAVE_SYS_TIME_H
86 #include <sys/time.h>
87 #endif
88 #ifdef HAVE_TIME_H
89 #include <time.h>
90 #endif
91 #else
92 #if defined(TM_IN_SYS_TIME) && defined(HAVE_SYS_TIME_H)
93 #include <sys/time.h>
94 #elif defined(HAVE_TIME_H)
95 #include <time.h>
96 #endif
97 #endif
98 #ifdef X_S
99 #undef _XOPEN_SOURCE
100 #endif
101 #ifdef U_X
102 #undef __USE_XOPEN
103 #endif
104
105 #include <sys/stat.h>
106 #ifdef HAVE_FCNTL_H
107 #include <fcntl.h>
108 #endif
109 #if defined(HAVE_LINUX_FALLOC_H) && !defined(FALLOC_FL_KEEP_SIZE)
110 #include <linux/falloc.h>
111 #endif
112 #ifdef HAVE_SYS_FILE_H
113 #include <sys/file.h>
114 #endif
115 #if defined(HAVE_DIRENT_H) || defined(__CYGWIN__)
116 #if defined(__CYGWIN__) && !defined(NAME_MAX)
117 #define NAME_MAX 255
118 #endif
119 #include <dirent.h>
120 #elif defined(HAVE_SYS_NDIR_H)
121 #include <sys/ndir.h>
122 #elif defined(HAVE_SYS_DIR_H)
123 #include <sys/dir.h>
124 #ifndef dirent
125 #define dirent direct
126 #endif
127 #elif defined(HAVE_NDIR_H)
128 #include <ndir.h>
129 #endif
130 #include <signal.h>
131 #ifdef HAVE_SYS_WAIT_H
132 #include <sys/wait.h>
133 #endif
134 #ifdef HAVE_SYS_SELECT_H
135 #include <sys/select.h>
136 #endif
137 #ifdef HAVE_SYS_RESOURCE_H
138 #include <sys/resource.h>
139 #endif
140 #ifdef HAVE_SYS_CYGWIN_H
141 #include <sys/cygwin.h>
142 #endif
143 #ifdef HAVE_UWIN_H
144 #include <uwin.h>
145 #endif
146 #ifdef HAVE_INTERIX_INTERIX_H
147 #include <interix/interix.h>
148 #endif
149 #ifdef HAVE_IO_H
150 #include <io.h>
151 #endif
152 #ifdef HAVE_PROCESS_H
153 #include <process.h>
154 #endif
155 #ifdef HAVE_CYGWIN_PROCESS_H
156 #include <cygwin/process.h>
157 #endif
158 #ifdef HAVE_CYGWIN_VERSION_H
159 #include <cygwin/version.h>
160 #endif
161 #ifdef HAVE_UNIXLIB_H
162 #include <unixlib.h>
163 #endif
164 #ifdef HAVE_SYS_UTSNAME_H
165 #include <sys/utsname.h>
166 #endif
167 #ifdef HAVE_PWD_H
168 #include <pwd.h>
169 #endif
170 #ifdef HAVE_GRP_H
171 #include <grp.h>
172 #endif
173 #ifdef HAVE_MALLOC_H
174 #include <malloc.h>
175 #endif
176 #ifdef HAVE_ALLOCA_H
177 #include <alloca.h>
178 #endif
179 #ifdef HAVE_SEARCH_H
180 #include <search.h>
181 #endif
182
183 #ifdef HAVE_NETINET_IN_SYSTM_H
184 #include <netinet/in_systm.h>
185 #else
186 #ifdef HAVE_NETINET_IN_SYSTEM_H
187 #include <netinet/in_system.h>
188 #endif
189 #endif
190 #include <netdb.h>
191 #include <sys/socket.h>
192 #include <netinet/in.h>
193 #ifdef HAVE_NETINET_IP_H
194 #include <netinet/ip.h>
195 #endif
196 #ifdef HAVE_ARPA_INET_H
197 #include <arpa/inet.h>
198 #endif
199 #ifdef HAVE_UTIME_H
200 #include <utime.h>
201 #endif
202
203 #ifdef HAVE_LOCALE_H
204 #include <locale.h>
205 #endif
206
207 #ifdef HAVE_SSL
208
209 #ifdef HAVE_OPENSSL
210
211 #if !defined(NO_SSL_CERTIFICATES) && defined(HAVE_OPENSSL_X509V3_H) && defined(HAVE_ASN1_STRING_TO_UTF8)
212 #define HAVE_SSL_CERTIFICATES
213 #endif
214 #if defined(OPENVMS) && defined(__VAX)
215 #define OPENSSL_NO_SHA512
216 #endif
217
218 #include <openssl/ssl.h>
219 #include <openssl/rand.h>
220 #ifdef HAVE_SSL_CERTIFICATES
221 #include <openssl/x509v3.h>
222 #endif
223 #include <openssl/err.h>
224 #include <openssl/crypto.h>
225
226 #ifdef HAVE_SSL_GET1_SESSION
227 #define SSL_SESSION_RESUME
228 #endif
229
230 #if defined(HAVE_CONFIG_VMS_H) && defined(OPENSSL_VERSION_NUMBER)
231 #if OPENSSL_VERSION_NUMBER >= 0x10100002L
232 #define HAVE_CRYPTO_SET_MEM_FUNCTIONS_2
233 #endif
234 #define HAVE_CRYPTO_SET_MEM_FUNCTIONS_1
235 #endif
236
237 #endif
238
239 #ifdef HAVE_NSS
240 #include <nss_compat_ossl/nss_compat_ossl.h>
241 #endif
242
243 #endif
244
245 #if defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_1) && defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_2)
246 #undef HAVE_CRYPTO_SET_MEM_FUNCTIONS_1
247 #undef HAVE_CRYPTO_SET_MEM_FUNCTIONS_2
248 #endif
249 #if defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_1) || defined(HAVE_CRYPTO_SET_MEM_FUNCTIONS_2)
250 #define HAVE_CRYPTO_SET_MEM_FUNCTIONS
251 #endif
252
253
254 #if defined(G)
255 #if defined(HAVE_PNG_H)
256 #define PNG_THREAD_UNSAFE_OK
257 #include <png.h>
258 #elif defined(HAVE_LIBPNG_PNG_H)
259 #define PNG_THREAD_UNSAFE_OK
260 #include <libpng/png.h>
261 #endif /* #if defined(HAVE_PNG_H) */
262 #ifndef png_jmpbuf
263 #define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
264 #endif
265 #endif /* #if defined(G) */
266
267 #ifdef HAVE_SETJMP_H
268 #ifndef _SETJMP_H
269 #include <setjmp.h>
270 #endif /* _SETJMP_H */
271 #endif
272
273 #ifdef HAVE_TERMIOS_H
274 #include <termios.h>
275 #elif defined(HAVE_SGTTY_H)
276 #include <sgtty.h>
277 #endif
278
279 #if defined(HAVE_POLL_H) && defined(HAVE_POLL) && !defined(INTERIX) && !defined(__HOS_AIX__)
280 #define USE_POLL
281 #include <poll.h>
282 #endif
283
284 #if (defined(HAVE_EVENT_H) || defined(HAVE_EV_EVENT_H)) && (defined(HAVE_LIBEVENT) || defined(HAVE_LIBEV)) && !defined(OPENVMS) && !defined(BEOS) && !defined(OPENVMS) && !defined(DOS)
285 #if defined(HAVE_EVENT_H)
286 #include <event.h>
287 #else
288 #include <ev-event.h>
289 #endif
290 #define USE_LIBEVENT
291 #endif
292
293 #ifdef HAVE_OPENMP
294 #include <omp.h>
295 #define SMP_ALIGN 256
296 #else
297 #define omp_get_num_threads() 1
298 #define omp_get_thread_num() 0
299 #define SMP_ALIGN 1
300 #endif
301 #if (defined(__alpha__) || defined(__alpha)) && !defined(__alpha_bwx__)
302 #define OPENMP_NONATOMIC 1
303 #else
304 #define OPENMP_NONATOMIC 0
305 #endif
306
307 #ifdef HAVE_LONG_LONG
308 #define longlong long long
309 #define ulonglong unsigned long long
310 #else
311 #define longlong double
312 #define ulonglong double
313 #endif
314
315 #if defined(__INTERIX) && defined(HAVE_STRTOQ)
316 extern quad_t
317 #if defined(__cdecl) || defined(_MSC_VER)
318 __cdecl
319 #endif
320 strtoq(const char *, char **, int);
321 #endif
322
323 #define stringify_internal_error(arg) #arg
324 #define stringify(arg) stringify_internal_error(arg)
325
326 #define array_elements(a) (sizeof(a) / sizeof(*a))
327
328 #include "os_depx.h"
329
330 #include "setup.h"
331
332 #define LINKS_2
333
334 #ifdef HAVE_POINTER_COMPARISON_BUG
335 #define DUMMY ((void *)1L)
336 #else
337 #define DUMMY ((void *)-1L)
338 #endif
339
340 #define cast_const_char (const char *)
341 #define cast_char (char *)
342 #define cast_uchar (unsigned char *)
343
344 /* avoid unreachable code warnings */
value_0(void)345 static inline int value_0(void)
346 {
347 return 0;
348 }
349
value_1(void)350 static inline int value_1(void)
351 {
352 return 1;
353 }
354
355 #if defined(C_LITTLE_ENDIAN)
356 #define big_endian (value_0())
357 #elif defined(C_BIG_ENDIAN)
358 #define big_endian (value_1())
359 #else
360 #define big_endian (htons(0x1234) == 0x1234)
361 #endif
362
363 #ifdef OPENVMS
364 #define RET_OK 1 /* SS$_NORMAL */
365 #define RET_ERROR 3586 /* SS$_LINEABRT */
366 #define RET_SIGNAL 2096 /* SS$_CANCEL */
367 #define RET_SYNTAX 20 /* SS$_BADPARAM */
368 #define RET_FATAL 44 /* SS$_ABORT */
369 #define RET_INTERNAL 44 /* SS$_ABORT */
370 #else
371 #define RET_OK 0
372 #define RET_ERROR 1
373 #define RET_SIGNAL 2
374 #define RET_SYNTAX 3
375 #define RET_FATAL 4
376 #define RET_INTERNAL 127
377 #endif
378
379 #ifndef HAVE_SNPRINTF
380 int my_snprintf(char *, int n, char *format, ...) PRINTF_FORMAT(3, 4);
381 #define snprintf my_snprintf
382 #endif
383 #ifndef HAVE_RAISE
384 int raise(int);
385 #endif
386 #ifndef HAVE_GETTIMEOFDAY
387 struct timeval {
388 long tv_sec;
389 long tv_usec;
390 };
391 struct timezone {
392 int tz_minuteswest;
393 int tz_dsttime;
394 };
395 int gettimeofday(struct timeval *tv, struct timezone *tz);
396 #endif
397 #ifndef HAVE_TEMPNAM
398 char *tempnam(const char *dir, const char *pfx);
399 #endif
400 #ifndef HAVE_STRDUP
401 char *strdup(const char *s);
402 #endif
403 #ifndef HAVE_STRTOL
404 long strtol(const char *, char **, int);
405 #endif
406 #ifndef HAVE_STRTOUL
407 unsigned long strtoul(const char *, char **, int);
408 #endif
409 #ifndef HAVE_STRTOD
410 double strtod(const char *nptr, char **endptr);
411 #endif
412 #ifndef HAVE_STRLEN
413 size_t strlen(const char *s);
414 #endif
415 #ifndef HAVE_STRCPY
416 char *strcpy(char *dst, const char *src);
417 #endif
418 #ifndef HAVE_STRNLEN
419 size_t strnlen(const char *s, size_t max);
420 #endif
421 #ifndef HAVE_STRNCPY
422 char *strncpy(char *dst, const char *src, size_t len);
423 #endif
424 #ifndef HAVE_STRCHR
425 char *strchr(const char *s, int c);
426 #endif
427 #ifndef HAVE_STRRCHR
428 char *strrchr(const char *s, int c);
429 #endif
430 #ifndef HAVE_STRCMP
431 int strcmp(const char *s1, const char *s2);
432 #endif
433 #ifndef HAVE_STRNCMP
434 int strncmp(const char *s1, const char *s2, size_t n);
435 #endif
436 #ifndef HAVE_STRCSPN
437 size_t strcspn(const char *s, const char *reject);
438 #endif
439 #ifndef HAVE_STRSPN
440 size_t strspn(const char *s, const char *accept);
441 #endif
442 #ifndef HAVE_STRSTR
443 char *strstr(const char *haystack, const char *needle);
444 #endif
445 #ifndef HAVE_MEMCHR
446 void *memchr(const void *s, int c, size_t length);
447 #endif
448 #ifndef HAVE_MEMRCHR
449 void *memrchr(const void *s, int c, size_t length);
450 #endif
451 #ifndef HAVE_MEMCMP
452 int memcmp(const void *, const void *, size_t);
453 #endif
454 #ifndef HAVE_MEMCPY
455 void *memcpy(void *, const void *, size_t);
456 #endif
457 #ifndef HAVE_MEMMOVE
458 void *memmove(void *, const void *, size_t);
459 #endif
460 #ifndef HAVE_MEMSET
461 void *memset(void *, int, size_t);
462 #endif
463 #ifndef HAVE_MEMMEM
464 void *memmem(const void *haystack, size_t hs, const void *needle, size_t ns);
465 #endif
466 #ifndef HAVE_STRERROR
467 char *strerror(int);
468 #endif
469
470 #define EINTRLOOPX(ret_, call_, x_) \
471 do { \
472 (ret_) = (call_); \
473 } while ((ret_) == (x_) && errno == EINTR)
474
475 #define EINTRLOOP(ret_, call_) EINTRLOOPX(ret_, call_, -1)
476
477 #define ENULLLOOP(ret_, call_) \
478 do { \
479 errno = 0; \
480 (ret_) = (call_); \
481 } while (!(ret_) && errno == EINTR)
482
483 #if defined(HAVE_PTHREAD_SIGMASK) && !defined(__BIONIC__)
do_sigprocmask(int how,const sigset_t * set,sigset_t * oset)484 static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
485 {
486 int r;
487 r = pthread_sigmask(how, set, oset);
488 if (r) {
489 errno = r;
490 return -1;
491 }
492 return 0;
493 }
494 #elif defined(HAVE_SIGPROCMASK)
495 #define do_sigprocmask sigprocmask
496 #else
497 #ifdef sigset_t
498 #undef sigset_t
499 #endif
500 #define sigset_t int
501 #ifndef SIG_BLOCK
502 #define SIG_BLOCK 0
503 #endif
504 #ifndef SIG_SETMASK
505 #define SIG_SETMASK 2
506 #endif
do_sigprocmask(int how,const sigset_t * set,sigset_t * oset)507 static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
508 {
509 sigset_t old = 0;
510 #if defined(HAVE_SIGBLOCK) && defined(HAVE_SIGSETMASK)
511 switch (how) {
512 case SIG_BLOCK:
513 old = sigblock(*set);
514 break;
515 case SIG_SETMASK:
516 old = sigsetmask(*set);
517 break;
518 }
519 #endif
520 if (oset) *oset = old;
521 return 0;
522 }
523 #ifdef sigdelset
524 #undef sigdelset
525 #endif
526 #define sigdelset(x, s) (*(x) &= ~(1 << (s)), 0)
527 #ifndef HAVE_SIGDELSET
528 #define HAVE_SIGDELSET 1
529 #endif
530 #ifdef HAVE_SIGFILLSET
531 #undef HAVE_SIGFILLSET
532 #endif
533 #endif
534 #ifdef HAVE_SIGFILLSET
sig_fill_set(sigset_t * set)535 static inline void sig_fill_set(sigset_t *set)
536 {
537 sigfillset(set);
538 }
539 #else
sig_fill_set(sigset_t * set)540 static inline void sig_fill_set(sigset_t *set)
541 {
542 memset(set, -1, sizeof(sigset_t));
543 }
544 #endif
545
546 #define option option_dirty_workaround_for_name_clash_with_include_on_cygwin
547 #define table table_dirty_workaround_for_name_clash_with_libraries_on_macos
548 #define scroll scroll_dirty_workaround_for_name_clash_with_libraries_on_macos
549 #define list list_dirty_workaround_for_name_clash_in_stl_with_class_list
550
551 #ifndef G
552 #define F 0
553 #else
554 extern int F;
555 #endif
556
557 #if defined(DEBUG)
558 #if defined(G)
559 #define NO_GFX do {if (F) internal_error("call to text-only function");} while (0)
560 #define NO_TXT do {if (!F) internal_error("call to graphics-only function");} while (0)
561 #else
562 #define NO_GFX do {} while (0)
563 #define NO_TXT this_should_not_be_compiled
564 #endif
565 #else
566 #define NO_GFX do {} while (0)
567 #define NO_TXT do {} while (0)
568 #endif
569
570 #ifndef G
571 #define gf_val(x, y) (x)
572 #define GF(x)
573 #else
574 #define gf_val(x, y) (F ? (y) : (x))
575 #define GF(x) if (F) {x;}
576 #endif
577
578 #define MAX_STR_LEN 1024
579
580 #define BIN_SEARCH(entries, eq, ab, key, result) \
581 { \
582 int s_ = 0, e_ = (entries) - 1; \
583 (result) = -1; \
584 while (s_ <= e_) { \
585 int m_ = (int)(((unsigned)s_ + (unsigned)e_) / 2); \
586 if (eq((m_), (key))) { \
587 (result) = m_; \
588 break; \
589 } \
590 if (ab((m_), (key))) e_ = m_ - 1; \
591 else s_ = m_ + 1; \
592 } \
593 } \
594
595 /* error.c */
596
597 #if defined(DOS)
598 #define ANSI_BELL "\007"
599 #define ANSI_SET_BOLD ""
600 #define ANSI_CLEAR_BOLD ""
601 #else
602 #define ANSI_BELL "\007"
603 #define ANSI_SET_BOLD "\033[1m"
604 #define ANSI_CLEAR_BOLD "\033[0m"
605 #endif
606
607 #ifdef LEAK_DEBUG
608 extern unsigned alloc_overhead;
609 #else
610 #define alloc_overhead 0
611 #endif
612
613 void *do_not_optimize_here(void *p);
614 void init_heap(void);
615 void check_memory_leaks(void);
616 void error(const char *, ...) PRINTF_FORMAT(1, 2);
617 void fatal_exit(const char *, ...) PRINTF_FORMAT(1, 2) ATTR_NORETURN;
618 void debug_msg(const char *, ...) PRINTF_FORMAT(1, 2);
619 void int_error(const char *, ...) PRINTF_FORMAT(1, 2)
620 #ifndef NO_IE
621 ATTR_NORETURN
622 #endif
623 ;
624 extern int errline;
625 extern unsigned char *errfile;
626
627 #define internal_error errfile = cast_uchar __FILE__, errline = __LINE__, int_error
628 #define debug errfile = cast_uchar __FILE__, errline = __LINE__, debug_msg
629
630 void fatal_tty_exit(void);
631
632 #ifdef __ICC
633 /* ICC OpenMP bug */
634 #define overalloc_condition 0
635 #else
636 #define overalloc_condition 1
637 #endif
638
639 #define overalloc_at(f, l) \
640 do { \
641 fatal_exit("ERROR: attempting to allocate too large block at %s:%d", f, l);\
642 } while (overalloc_condition) /* while (1) is not a typo --- it's here to allow the compiler
643 that doesn't know that fatal_exit doesn't return to do better
644 optimizations */
645
646 #define overalloc() overalloc_at(__FILE__, __LINE__)
647
648 #define overflow() \
649 do { \
650 fatal_exit("ERROR: arithmetic overflow at %s:%d", __FILE__, __LINE__);\
651 } while (1)
652
test_int_overflow(int x,int y,int * result)653 static inline int test_int_overflow(int x, int y, int *result)
654 {
655 #ifdef HAVE___BUILTIN_ADD_OVERFLOW
656 return __builtin_add_overflow(x, y, result);
657 #else
658 int z = *result = (int)((unsigned)(x) + (unsigned)(y));
659 return ~((unsigned)(x) ^ (unsigned)(y)) & ((unsigned)(x) ^ ((unsigned)(z))) & (1U << (sizeof(unsigned) * 8 - 1));
660 #endif
661 }
662
safe_add_function(int x,int y,unsigned char * file,int line)663 static inline int safe_add_function(int x, int y, unsigned char *file, int line)
664 {
665 int result;
666 #if !defined(HAVE___BUILTIN_ADD_OVERFLOW) && defined(HAVE_GCC_ASSEMBLER) && (defined(__i386__) || defined(__x86_64__))
667 unsigned char ovf;
668 __asm__ ("addl %2, %0; seto %1":"=r"(result),
669 #if defined(__PATHSCALE__) || defined(__OPEN64__)
670 "=q" /* a bug in the PathScale and Open64 compiler */
671 #else
672 "=qm"
673 #endif
674 (ovf):"g"(y),"0"(x));
675 if (ovf)
676 fatal_exit("ERROR: arithmetic overflow at %s:%d: %d + %d", file, line, (x), (y));
677 return result;
678 #endif
679 if (test_int_overflow(x, y, &result))
680 fatal_exit("ERROR: arithmetic overflow at %s:%d: %d + %d", file, line, (x), (y));
681 return result;
682 }
683
684 #define safe_add(x, y) safe_add_function(x, y, (unsigned char *)__FILE__, __LINE__)
685
686 #ifdef HAVE_GCC_ASSEMBLER
memory_barrier(void * p)687 static inline void *memory_barrier(void *p)
688 {
689 void *o;
690 __asm__ volatile("" : "=r"(o) : "0"(p) : "memory");
691 return o;
692 }
693 #else
694 #define memory_barrier(p) do_not_optimize_here(p)
695 #endif
696
697 #ifdef LEAK_DEBUG
698
699 extern my_uintptr_t mem_amount;
700 extern my_uintptr_t mem_blocks;
701
702 #endif
703
704 #ifdef LEAK_DEBUG
705
706 void *debug_mem_alloc(unsigned char *, int, size_t, int);
707 void *debug_mem_calloc(unsigned char *, int, size_t, int);
708 void debug_mem_free(unsigned char *, int, void *);
709 void *debug_mem_realloc(unsigned char *, int, void *, size_t, int);
710 void set_mem_comment(void *, unsigned char *, int);
711 unsigned char *get_mem_comment(void *);
712
713 #define mem_alloc(x) debug_mem_alloc((unsigned char *)__FILE__, __LINE__, x, 0)
714 #define mem_calloc(x) debug_mem_calloc((unsigned char *)__FILE__, __LINE__, x, 0)
715 #define mem_free(x) debug_mem_free((unsigned char *)__FILE__, __LINE__, x)
716 #define mem_realloc(x, y) debug_mem_realloc((unsigned char *)__FILE__, __LINE__, x, y, 0)
717
718 #define mem_alloc_mayfail(x) debug_mem_alloc((unsigned char *)__FILE__, __LINE__, x, 1)
719 #define mem_calloc_mayfail(x) debug_mem_calloc((unsigned char *)__FILE__, __LINE__, x, 1)
720 #define mem_realloc_mayfail(x, y) debug_mem_realloc((unsigned char *)__FILE__, __LINE__, x, y, 1)
721
722 #else
723
724 void *mem_alloc_(size_t size, int mayfail);
725 void *mem_calloc_(size_t size, int mayfail);
726 void mem_free(void *p);
727 void *mem_realloc_(void *p, size_t size, int mayfail);
728
729 #define mem_alloc(x) mem_alloc_(x, 0)
730 #define mem_calloc(x) mem_calloc_(x, 0)
731 #define mem_realloc(x, y) mem_realloc_(x, y, 0)
732
733 #define mem_alloc_mayfail(x) mem_alloc_(x, 1)
734 #define mem_calloc_mayfail(x) mem_calloc_(x, 1)
735 #define mem_realloc_mayfail(x, y) mem_realloc_(x, y, 1)
736
737
debug_mem_alloc(unsigned char * f,int l,size_t s,int mayfail)738 static inline void *debug_mem_alloc(unsigned char *f, int l, size_t s, int mayfail) { return mem_alloc_(s, mayfail); }
debug_mem_calloc(unsigned char * f,int l,size_t s,int mayfail)739 static inline void *debug_mem_calloc(unsigned char *f, int l, size_t s, int mayfail) { return mem_calloc_(s, mayfail); }
debug_mem_free(unsigned char * f,int l,void * p)740 static inline void debug_mem_free(unsigned char *f, int l, void *p) { mem_free(p); }
debug_mem_realloc(unsigned char * f,int l,void * p,size_t s,int mayfail)741 static inline void *debug_mem_realloc(unsigned char *f, int l, void *p, size_t s, int mayfail) { return mem_realloc_(p, s, mayfail); }
set_mem_comment(void * p,unsigned char * c,int l)742 static inline void set_mem_comment(void *p, unsigned char *c, int l) {}
get_mem_comment(void * p)743 static inline unsigned char *get_mem_comment(void *p){return (unsigned char *)"";}
744 #endif
745
746 #if !(defined(LEAK_DEBUG) && defined(LEAK_DEBUG_LIST))
747
748 unsigned char *memacpy(const unsigned char *src, size_t len);
749 unsigned char *stracpy(const unsigned char *src);
750
751 #else
752
753 unsigned char *debug_memacpy(unsigned char *f, int l, const unsigned char *src, size_t len);
754 #define memacpy(s, l) debug_memacpy((unsigned char *)__FILE__, __LINE__, s, l)
755
756 unsigned char *debug_stracpy(unsigned char *f, int l, const unsigned char *src);
757 #define stracpy(s) debug_stracpy((unsigned char *)__FILE__, __LINE__, s)
758
759 #endif
760
761 #if defined(LEAK_DEBUG) && defined(LEAK_DEBUG_LIST)
762 #define GTM_MOST_ALLOCATED 0
763 #define GTM_LARGEST_BLOCKS 1
764 unsigned char *get_top_memory(int mode, unsigned n);
765 #endif
766
767 #if !defined(HAVE_SIGSETJMP) || !defined(HAVE_SETJMP_H)
768 #ifdef OOPS
769 #undef OOPS
770 #endif
771 #endif
772
773 #ifndef OOPS
774 #define pr(code) if (1) {code;} else
nopr(void)775 static inline void nopr(void) {}
xpr(void)776 static inline void xpr(void) {}
777 #else
778 sigjmp_buf *new_stack_frame(void);
779 void xpr(void);
780 #define pr(code) if (!sigsetjmp(*new_stack_frame(), 1)) {do {code;} while (0); xpr();} else
781 void nopr(void);
782 #endif
783
784 /* inline */
785
786 #define ALLOC_GR 0x040 /* must be power of 2 */
787
788 #define get_struct_(ptr, struc, entry) ((struc *)((char *)(ptr) - offsetof(struc, entry)))
789 #define get_struct(ptr, struc, entry) ((void)(&get_struct_(ptr, struc, entry)->entry == (ptr)), get_struct_(ptr, struc, entry))
790
791 struct list_head {
792 struct list_head *next;
793 struct list_head *prev;
794 };
795
796 #ifdef DEBUG
corrupted_list_entry(unsigned char * file,int line,const char * msg,struct list_head * l,struct list_head * a)797 static inline void corrupted_list_entry(unsigned char *file, int line, const char *msg, struct list_head *l, struct list_head *a)
798 {
799 errfile = file;
800 errline = line;
801 int_error("%s %p, %p, %p, %p, %p, %p", msg, l, l->next, l->prev, l->next->prev, l->prev->next, a);
802 }
803 #define verify_list_entry(e) ((e)->next->prev != (e) || (e)->prev->next != (e) ? corrupted_list_entry(cast_uchar __FILE__, __LINE__, "corrupted link pointers", e, NULL) : (void)0)
804 #define verify_double_add(l, e) ((l) == (e) || (l)->next == (e) || (l)->prev == (e) ? corrupted_list_entry(cast_uchar __FILE__, __LINE__, "double add", l, e) : (void)0)
805 #else
806 #define verify_list_entry(e) ((void)0)
807 #define verify_double_add(l, e) ((void)0)
808 #endif
809
810 #define list_struct(ptr, struc) get_struct(ptr, struc, list_entry)
811 #define init_list(x) do { (x).next = &(x); (x).prev = &(x); } while (0)
812 #define list_empty(x) (verify_list_entry(&x), (x).next == &(x))
813 #define del_list_entry(x) do { verify_list_entry(x); (x)->next->prev = (x)->prev; (x)->prev->next = (x)->next; (x)->prev = (x)->next = NULL; } while (0)
814 #define del_from_list(x) del_list_entry(&(x)->list_entry)
815 #define add_after_list_entry(p, x) do { verify_double_add(p, x); verify_list_entry(p); (x)->next = (p)->next; (x)->prev = (p); (p)->next = (x); (x)->next->prev = (x); } while (0)
816 #define add_before_list_entry(p, x) do { verify_double_add(p, x); verify_list_entry(p); (x)->prev = (p)->prev; (x)->next = (p); (p)->prev = (x); (x)->prev->next = (x); } while (0)
817 #define add_to_list(l, x) add_after_list_entry(&(l), &(x)->list_entry)
818 #define add_to_list_end(l, x) add_before_list_entry(&(l), &(x)->list_entry)
819 #define add_after_pos(p, x) add_after_list_entry(&(p)->list_entry, &(x)->list_entry)
820 #define add_before_pos(p, x) add_before_list_entry(&(p)->list_entry, &(x)->list_entry)
821 #define fix_list_after_realloc(x) do { (x)->list_entry.prev->next = &(x)->list_entry; (x)->list_entry.next->prev = &(x)->list_entry; } while (0)
822 #define foreachfrom(struc, e, h, l, s) for ((h) = (s); verify_list_entry(h), (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); (h) = (h)->next)
823 #define foreach(struc, e, h, l) foreachfrom(struc, e, h, l, (l).next)
824 #define foreachbackfrom(struc, e, h, l, s) for ((h) = (s); verify_list_entry(h), (h) == &(l) ? 0 : ((e) = list_struct(h, struc), 1); (h) = (h)->prev)
825 #define foreachback(struc, e, h, l) foreachbackfrom(struc, e, h, l, (l).prev)
826 #define free_list(struc, l) do { while (!list_empty(l)) { struc *a__ = list_struct((l).next, struc); del_from_list(a__); mem_free(a__); } } while (0)
827
list_size(struct list_head * l)828 static inline unsigned long list_size(struct list_head *l)
829 {
830 struct list_head *e;
831 unsigned long n = 0;
832 for (e = l->next; e != l; e = e->next) n++;
833 return n;
834 }
835
836 #ifdef DEBUG
837 #define REORDER_LIST_ENTRIES
838 #endif
839
840 #ifndef REORDER_LIST_ENTRIES
841 #define list_entry_1st struct list_head list_entry;
842 #define list_entry_last
843 #define init_list_1st(x) { (x), (x) },
844 #define init_list_last(x)
845 #else
846 #define list_entry_1st
847 #define list_entry_last struct list_head list_entry;
848 #define init_list_1st(x)
849 #define init_list_last(x) { (x), (x) },
850 #endif
851
852 #define WHITECHAR(x) ((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
853 #define U(x) ((x) == '"' || (x) == '\'')
854
855
856 #define CI_BYTES 1
857 #define CI_FILES 2
858 #define CI_LOCKED 3
859 #define CI_LOADING 4
860 #define CI_TIMERS 5
861 #define CI_TRANSFER 6
862 #define CI_CONNECTING 7
863 #define CI_KEEP 8
864
865 /* string.c */
866
867 int snprint(unsigned char *s, int n, my_uintptr_t num);
868 int snzprint(unsigned char *s, int n, off_t num);
869 void add_to_strn(unsigned char **s, unsigned char *a);
870 void extend_str(unsigned char **s, int n);
871
872 #define init_str() init_str_x((unsigned char *)__FILE__, __LINE__)
873
init_str_x(unsigned char * file,int line)874 static inline unsigned char *init_str_x(unsigned char *file, int line)
875 {
876 unsigned char *p;
877
878 p=(unsigned char *)debug_mem_calloc(file, line, 1L, 0);
879 return p;
880 }
881
882 void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll);
883 void add_to_str(unsigned char **s, int *l, unsigned char *a);
884 void add_chr_to_str(unsigned char **s, int *l, unsigned char a);
885 void add_unsigned_num_to_str(unsigned char **s, int *l, off_t n);
886 void add_unsigned_long_num_to_str(unsigned char **s, int *l, my_uintptr_t n);
887 void add_num_to_str(unsigned char **s, int *l, off_t n);
888 void add_knum_to_str(unsigned char **s, int *l, off_t n);
889 long strtolx(unsigned char *c, unsigned char **end);
890 #if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ) || defined(HAVE_STRTOIMAX)
891 #define my_strtoll_t longlong
892 #else
893 #define my_strtoll_t long
894 #endif
895 my_strtoll_t my_strtoll(unsigned char *string, unsigned char **end);
896
897 void safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size);
898 #ifdef JS
899 void skip_nonprintable(unsigned char *txt);
900 #endif
901 /* case insensitive compare of 2 strings */
902 /* comparison ends after len (or less) characters */
903 /* return value: 1=strings differ, 0=strings are same */
upcase(unsigned a)904 static inline unsigned upcase(unsigned a)
905 {
906 if (a >= 'a' && a <= 'z') a -= 0x20;
907 return a;
908 }
locase(unsigned a)909 static inline unsigned locase(unsigned a)
910 {
911 if (a >= 'A' && a <= 'Z') a += 0x20;
912 return a;
913 }
srch_cmp(unsigned char c1,unsigned char c2)914 static inline int srch_cmp(unsigned char c1, unsigned char c2)
915 {
916 return upcase(c1) != upcase(c2);
917 }
918 int casestrcmp(const unsigned char *s1, const unsigned char *s2);
919 int casecmp(const unsigned char *c1, const unsigned char *c2, size_t len);
920 int casestrstr(const unsigned char *h, const unsigned char *n);
921 unsigned hash_string(unsigned char *s);
xstrcmp(const unsigned char * s1,const unsigned char * s2)922 static inline int xstrcmp(const unsigned char *s1, const unsigned char *s2)
923 {
924 if (!s1 && !s2) return 0;
925 if (!s1) return -1;
926 if (!s2) return 1;
927 return strcmp(cast_const_char s1, cast_const_char s2);
928 }
929
cmpbeg(const unsigned char * str,const unsigned char * b)930 static inline int cmpbeg(const unsigned char *str, const unsigned char *b)
931 {
932 while (*str && upcase(*str) == upcase(*b)) str++, b++;
933 return !!*b;
934 }
935
936
937 /* os_dep.c */
938
939 #ifdef HAVE_LONG_LONG
940 typedef unsigned long long uttime;
941 typedef unsigned long long tcount;
942 #else
943 typedef unsigned long uttime;
944 typedef unsigned long tcount;
945 #endif
946
947 extern int page_size;
948
949 #if defined(HAVE_GPM_H) && defined(HAVE_LIBGPM)
950 #define USE_GPM
951 #endif
952
953 #if defined(OS2) && defined(HAVE_UMALLOC_H) && defined(HAVE__MSIZE) && defined(HAVE__UCREATE) && defined(HAVE__UOPEN) && defined(HAVE__UDEFAULT) && defined(HAVE_BEGINTHREAD)
954 #define OS2_ADVANCED_HEAP
955 void *virtual_alloc(size_t len);
956 void virtual_free(void *ptr, size_t len);
957 void *os2_orig_malloc(size_t len);
958 #define MEMORY_BIGALLOC
959 extern unsigned long mem_bigalloc;
960 extern unsigned long blocks_bigalloc;
961 #define MEMORY_REQUESTED
962 extern unsigned long mem_requested;
963 extern unsigned long blocks_requested;
964 #endif
965
966 #ifdef OPENVMS
967 #define VMS_ADVANCED_HEAP
968 void *virtual_alloc(size_t len);
969 void virtual_free(void *ptr, size_t len);
970 #define MEMORY_BIGALLOC
971 extern unsigned long mem_bigalloc;
972 extern unsigned long blocks_bigalloc;
973 #endif
974
975 struct terminal;
976
977 struct open_in_new {
978 unsigned char *text;
979 unsigned char *hk;
980 int (* const *open_window_fn)(struct terminal *, unsigned char *, unsigned char *);
981 };
982
983 void close_fork_tty(void);
984 int get_system_env(void);
985 int is_twterm(void);
986 int is_screen(void);
987 int is_xterm(void);
988 void get_terminal_size(int *, int *);
989 void handle_terminal_resize(void (*)(int, int), int *x, int *y);
990 void unhandle_terminal_resize(void);
991 void set_nonblock(int);
992 int c_pipe(int [2]);
993 int c_dup(int oh);
994 int c_socket(int, int, int);
995 int c_accept(int, struct sockaddr *, socklen_t *);
996 int c_open(unsigned char *, int);
997 int c_open3(unsigned char *, int, int);
998 DIR *c_opendir(unsigned char *);
999 #ifdef HAVE_OPEN_PREALLOC
1000 int open_prealloc(unsigned char *, int, int, off_t);
1001 #endif
1002 int get_input_handle(void);
1003 int get_output_handle(void);
1004 int get_ctl_handle(void);
1005 #ifdef OS_SETRAW
1006 int setraw(int ctl, int save);
1007 void setcooked(int ctl);
1008 #endif
1009 void want_draw(void);
1010 void done_draw(void);
1011 void terminate_osdep(void);
1012 void save_gpm_signals(void);
1013 void restore_gpm_signals(void);
1014 void *handle_mouse(int, void (*)(void *, unsigned char *, int), void *);
1015 void unhandle_mouse(void *);
1016 void add_gpm_version(unsigned char **s, int *l);
1017 #ifdef OPENVMS
1018 extern int vms_thread_high_priority;
1019 #endif
1020 int start_thread(void (*)(void *, int), void *, int, int);
1021 unsigned char *get_clipboard_text(struct terminal *);
1022 void set_clipboard_text(struct terminal *, unsigned char *);
1023 int clipboard_support(struct terminal *);
1024 int is_winnt(void);
1025 int get_windows_cp(int cons);
1026 void set_window_title(unsigned char *);
1027 unsigned char *get_window_title(void);
1028 int is_safe_in_shell(unsigned char);
1029 unsigned char *escape_path(unsigned char *);
1030 void check_shell_security(unsigned char **);
1031 void check_filename(unsigned char **);
1032 int check_shell_url(unsigned char *);
1033 void do_signal(int sig, void (*handler)(int));
1034 uttime get_time(void);
1035 time_t get_absolute_seconds(void);
1036 uttime get_absolute_time(void);
1037 void ignore_signals(void);
1038 void block_stdin(void);
1039 void unblock_stdin(void);
1040 void init_page_size(void);
1041 void init_os(void);
1042 void init_os_terminal(void);
1043 void get_path_to_exe(void);
1044 int os_get_system_name(unsigned char *buffer);
1045 unsigned char *os_conv_to_external_path(unsigned char *, unsigned char *);
1046 unsigned char *os_fixup_external_program(unsigned char *);
1047 int exe(unsigned char *, int);
1048 #ifdef WIN
1049 int exe_on_background(unsigned char *, unsigned char *);
1050 int windows_charset(void);
1051 #define HAVE_EXE_ON_BACKGROUND
1052 #endif
1053 int resize_window(int, int);
1054 int can_resize_window(struct terminal *);
1055 int can_open_os_shell(int);
1056 unsigned char *links_xterm(void);
1057 struct open_in_new *get_open_in_new(int);
1058 void set_highpri(void);
1059 #if defined(OPENVMS) && defined(GRDRV_X)
1060 int vms_x11_fd(int ef);
1061 #endif
1062
1063 void os_free_clipboard(void);
1064
1065 void os_seed_random(unsigned char **pool, int *pool_size);
1066 int os_send_fg_cookie(int);
1067 int os_receive_fg_cookie(int);
1068 extern int need_detach_console;
1069 void os_detach_console(void);
test_detach_console(void)1070 static inline void test_detach_console(void)
1071 {
1072 if (need_detach_console) {
1073 need_detach_console = 0;
1074 os_detach_console();
1075 }
1076 }
1077 int os_default_language(void);
1078 int os_default_charset(void);
1079
1080 void save_terminal(void);
1081 void restore_terminal(void);
1082
1083 #ifdef WIN
1084 #define OS_REPORT_ERROR_BUFFER 8192
1085 #else
1086 #define OS_REPORT_ERROR_BUFFER 4096
1087 #endif
1088 void os_report_error_va(const char *caption, const char *msg, va_list l);
1089 void os_report_error(const char *caption, const char *msg, ...);
1090
1091 /* memory.c */
1092
1093 #define SH_CHECK_QUOTA 0
1094 #define SH_FREE_SOMETHING 1
1095 #define SH_FREE_ALL 2
1096
1097 #define ST_SOMETHING_FREED 1
1098 #define ST_CACHE_EMPTY 2
1099
1100 #define MF_GPI 1
1101
1102 void heap_trim(void);
1103 int shrink_memory(int, int);
1104 void register_cache_upcall(int (*)(int), int, unsigned char *);
1105 void free_all_caches(void);
1106 extern int malloc_try_hard;
1107 int out_of_memory_fl(int flags, unsigned char *msg, size_t size, unsigned char *file, int line);
1108 #define out_of_memory(flags, msg, size) out_of_memory_fl(flags, msg, size, (unsigned char *)__FILE__, __LINE__)
1109
1110 #ifndef DEBUG_TEST_FREE
1111 #define debug_test_free(file, line)
1112 #else
1113 void debug_test_free(unsigned char *file, int line);
1114 #endif
1115
1116 /* select.c */
1117
1118 #ifndef FD_SETSIZE
1119 #define FD_SETSIZE (sizeof(fd_set) * 8)
1120 #endif
1121
1122 #define NBIT(p) (sizeof((p)->fds_bits[0]) * 8)
1123
1124 #ifndef FD_SET
1125 #define FD_SET(n, p) ((p)->fds_bits[(n)/NBIT(p)] |= (1 << ((n) % NBIT(p))))
1126 #endif
1127 #ifndef FD_CLR
1128 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NBIT(p)] &= ~(1 << ((n) % NBIT(p))))
1129 #endif
1130 #ifndef FD_ISSET
1131 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NBIT(p)] & (1 << ((n) % NBIT(p))))
1132 #endif
1133 #ifndef FD_ZERO
1134 #define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
1135 #endif
1136
1137
1138 extern int terminate_loop;
1139
1140 int can_write(int fd);
1141 int can_read(int fd);
1142 int can_read_timeout(int fd, int sec);
1143 int close_std_handle(int);
1144 void restore_std_handle(int, int);
1145 unsigned long select_info(int);
1146 void reinit_child(void);
1147 void select_loop(void (*)(void));
1148 void terminate_select(void);
1149 void register_bottom_half(void (*)(void *), void *);
1150 void unregister_bottom_half(void (*)(void *), void *);
1151 void check_bottom_halves(void);
1152 void add_event_string(unsigned char **, int *, struct terminal *);
1153 struct timer;
1154 struct timer *install_timer(uttime, void (*)(void *), void *);
1155 void kill_timer(struct timer *);
1156 void portable_sleep(unsigned msec);
1157
1158 #define H_READ 0
1159 #define H_WRITE 1
1160
1161 void (*get_handler(int, int))(void *);
1162 void *get_handler_data(int);
1163 extern unsigned char *sh_file;
1164 extern int sh_line;
1165 void set_handlers_file_line(int, void (*)(void *), void (*)(void *), void *);
1166 #define set_handlers(a, b, c, d) (sh_file = (unsigned char *)__FILE__, sh_line = __LINE__, set_handlers_file_line(a, b, c, d))
1167 void clear_events(int, int);
1168 extern int signal_pipe[2];
1169 void install_signal_handler(int, void (*)(void *), void *, int);
1170 void interruptible_signal(int sig, int in);
1171 void block_signals(int except1, int except2);
1172 void unblock_signals(void);
1173 void set_sigcld(void);
1174 #ifdef HAVE_OPENMP
1175 int omp_start(void);
1176 void omp_end(void);
1177 #else
1178 #define omp_start() 1
1179 #define omp_end() do { } while (0)
1180 #endif
1181
1182 /* dns.c */
1183
1184 #ifdef USE_GETADDRINFO
1185 #define MAX_ADDRESSES 64
1186 #else
1187 #define MAX_ADDRESSES 1
1188 #endif
1189
1190 struct host_address {
1191 int af;
1192 unsigned char addr[16];
1193 unsigned scope_id;
1194 };
1195
1196 struct lookup_result {
1197 int n;
1198 struct host_address a[MAX_ADDRESSES];
1199 };
1200
1201 struct lookup_state {
1202 struct lookup_result addr;
1203 int addr_index;
1204 int dont_try_more_servers;
1205 int socks_port;
1206 int target_port;
1207 };
1208
1209 #ifdef SUPPORT_IPV6
1210 extern int support_ipv6;
1211 #else
1212 #define support_ipv6 0
1213 #endif
1214
1215 int numeric_ip_address(unsigned char *name, unsigned char address[4]);
1216 #ifdef SUPPORT_IPV6
1217 int numeric_ipv6_address(unsigned char *name, unsigned char address[16], unsigned *scope_id);
1218 #endif
1219 void rotate_addresses(struct lookup_result *);
1220 void do_real_lookup(unsigned char *, int, struct lookup_result *);
1221 int find_host(unsigned char *, struct lookup_result *, void **, void (*)(void *, int), void *);
1222 int find_host_no_cache(unsigned char *, struct lookup_result *, void **, void (*)(void *, int), void *);
1223 void kill_dns_request(void **);
1224 void dns_prefetch(unsigned char *);
1225 #if MAX_ADDRESSES > 1
1226 void dns_set_priority(unsigned char *, struct host_address *, int);
1227 #endif
1228 void dns_clear_host(unsigned char *);
1229 unsigned long dns_info(int type);
1230 unsigned char *print_address(struct host_address *);
1231 int ipv6_full_access(void);
1232 void init_dns(void);
1233
1234 /* cache.c */
1235
1236 struct cache_entry {
1237 list_entry_1st
1238 unsigned char *head;
1239 int http_code;
1240 unsigned char *redirect;
1241 off_t length;
1242 off_t max_length;
1243 int incomplete;
1244 int tgc;
1245 unsigned char *last_modified;
1246 time_t expire_time; /* 0 never, 1 always */
1247 off_t data_size;
1248 struct list_head frag; /* struct fragment */
1249 tcount count;
1250 tcount count2;
1251 int refcount;
1252 unsigned char *decompressed;
1253 size_t decompressed_len;
1254 unsigned char *ip_address;
1255 #ifdef HAVE_SSL
1256 unsigned char *ssl_info;
1257 unsigned char *ssl_authority;
1258 #endif
1259 list_entry_last
1260 unsigned char url[1];
1261 };
1262
1263 struct fragment {
1264 list_entry_1st
1265 off_t offset;
1266 off_t length;
1267 off_t real_length;
1268 list_entry_last
1269 unsigned char data[1];
1270 };
1271
1272 struct connection;
1273
1274 void init_cache(void);
1275 my_uintptr_t cache_info(int);
1276 my_uintptr_t decompress_info(int);
1277 int find_in_cache(unsigned char *, struct cache_entry **);
1278 int get_connection_cache_entry(struct connection *);
1279 int new_cache_entry(unsigned char *, struct cache_entry **);
1280 void detach_cache_entry(struct cache_entry *);
1281 int add_fragment(struct cache_entry *, off_t, const unsigned char *, off_t);
1282 int defrag_entry(struct cache_entry *);
1283 void truncate_entry(struct cache_entry *, off_t, int);
1284 void free_entry_to(struct cache_entry *, off_t);
1285 void delete_entry_content(struct cache_entry *);
1286 void delete_cache_entry(struct cache_entry *e);
1287 void trim_cache_entry(struct cache_entry *e);
1288
1289 /* sched.c */
1290
1291 #ifdef HAVE_SSL
1292 typedef struct {
1293 SSL *ssl;
1294 SSL_CTX *ctx;
1295 tcount bytes_read;
1296 tcount bytes_written;
1297 int session_set;
1298 int session_retrieved;
1299 unsigned char *ca;
1300 } links_ssl;
1301 #endif
1302
1303 #define PRI_MAIN 0
1304 #define PRI_DOWNLOAD 0
1305 #define PRI_FRAME 1
1306 #define PRI_NEED_IMG 2
1307 #define PRI_IMG 3
1308 #define PRI_PRELOAD 4
1309 #define PRI_CANCEL 5
1310 #define N_PRI 6
1311
1312 struct remaining_info {
1313 int valid;
1314 off_t size, loaded, last_loaded, cur_loaded;
1315 off_t pos;
1316 uttime elapsed;
1317 uttime last_time;
1318 uttime dis_b;
1319 off_t data_in_secs[CURRENT_SPD_SEC];
1320 struct timer *timer;
1321 };
1322
1323 struct conn_info;
1324
1325 struct connection {
1326 list_entry_1st
1327 tcount count;
1328 unsigned char *url;
1329 unsigned char *prev_url; /* allocated string with referrer or NULL */
1330 int running;
1331 int state;
1332 int prev_error;
1333 off_t from;
1334 int pri[N_PRI];
1335 int no_cache;
1336 int sock1;
1337 int sock2;
1338 void *dnsquery;
1339 pid_t pid;
1340 int tries;
1341 int keepalive;
1342 tcount netcfg_stamp;
1343 struct list_head statuss;
1344 void *info;
1345 void *buffer;
1346 struct conn_info *newconn;
1347 void (*conn_func)(void *);
1348 struct cache_entry *cache;
1349 off_t received;
1350 off_t est_length;
1351 int unrestartable;
1352 int no_compress;
1353 struct remaining_info prg;
1354 struct timer *timer;
1355 int detached;
1356 unsigned char socks_proxy[MAX_STR_LEN];
1357 unsigned char dns_append[MAX_STR_LEN];
1358 struct lookup_state last_lookup_state;
1359 #ifdef HAVE_SSL
1360 links_ssl *ssl;
1361 int no_ssl_session;
1362 int no_tls;
1363 #endif
1364 list_entry_last
1365 };
1366
1367 extern tcount netcfg_stamp;
1368
1369 extern struct list_head queue;
1370
1371 struct k_conn {
1372 list_entry_1st
1373 void (*protocol)(struct connection *);
1374 unsigned char *host;
1375 int port;
1376 int conn;
1377 uttime timeout;
1378 uttime add_time;
1379 int protocol_data;
1380 #ifdef HAVE_SSL
1381 links_ssl *ssl;
1382 #endif
1383 struct lookup_state last_lookup_state;
1384 list_entry_last
1385 };
1386
1387 extern struct list_head keepalive_connections;
1388
1389 #define NC_ALWAYS_CACHE 0
1390 #define NC_CACHE 1
1391 #define NC_IF_MOD 2
1392 #define NC_RELOAD 3
1393 #define NC_PR_NO_CACHE 4
1394
1395 #define S_WAIT 0
1396 #define S_DNS 1
1397 #define S_CONN 2
1398 #define S_CONN_ANOTHER 3
1399 #define S_SOCKS_NEG 4
1400 #define S_SSL_NEG 5
1401 #define S_SENT 6
1402 #define S_LOGIN 7
1403 #define S_GETH 8
1404 #define S_PROC 9
1405 #define S_TRANS 10
1406
1407 #define S__OK (-2000000000)
1408 #define S_INTERRUPTED (-2000000001)
1409 #define S_INTERNAL (-2000000002)
1410 #define S_OUT_OF_MEM (-2000000003)
1411 #define S_NO_DNS (-2000000004)
1412 #define S_NO_PROXY_DNS (-2000000005)
1413 #define S_CANT_WRITE (-2000000006)
1414 #define S_CANT_READ (-2000000007)
1415 #define S_MODIFIED (-2000000008)
1416 #define S_BAD_URL (-2000000009)
1417 #define S_BAD_PROXY (-2000000010)
1418 #define S_TIMEOUT (-2000000011)
1419 #define S_RESTART (-2000000012)
1420 #define S_STATE (-2000000013)
1421 #define S_CYCLIC_REDIRECT (-2000000014)
1422 #define S_LARGE_FILE (-2000000015)
1423 #define S_BLOCKED_URL (-2000000016)
1424 #define S_SMB_NOT_ALLOWED (-2000000017)
1425 #define S_FILE_NOT_ALLOWED (-2000000018)
1426 #define S_NO_PROXY (-2000000019)
1427
1428 #define S_HTTP_ERROR (-2000000100)
1429 #define S_HTTP_100 (-2000000101)
1430 #define S_HTTP_204 (-2000000102)
1431 #define S_HTTPS_FWD_ERROR (-2000000103)
1432 #define S_INVALID_CERTIFICATE (-2000000104)
1433 #define S_DOWNGRADED_METHOD (-2000000105)
1434 #define S_INSECURE_CIPHER (-2000000106)
1435
1436 #define S_FILE_TYPE (-2000000200)
1437 #define S_FILE_ERROR (-2000000201)
1438
1439 #define S_FTP_ERROR (-2000000300)
1440 #define S_FTP_UNAVAIL (-2000000301)
1441 #define S_FTP_LOGIN (-2000000302)
1442 #define S_FTP_PORT (-2000000303)
1443 #define S_FTP_NO_FILE (-2000000304)
1444 #define S_FTP_FILE_ERROR (-2000000305)
1445
1446 #define S_SSL_ERROR (-2000000400)
1447 #define S_NO_SSL (-2000000401)
1448
1449 #define S_BAD_SOCKS_VERSION (-2000000500)
1450 #define S_SOCKS_REJECTED (-2000000501)
1451 #define S_SOCKS_NO_IDENTD (-2000000502)
1452 #define S_SOCKS_BAD_USERID (-2000000503)
1453 #define S_SOCKS_UNKNOWN_ERROR (-2000000504)
1454
1455 #define S_NO_SMB_CLIENT (-2000000600)
1456
1457 #define S_WAIT_REDIR (-2000000700)
1458
1459 #define S_UNKNOWN_ERROR (-2000000800)
1460
1461 #define S_MAX (-2000000900)
1462
1463
1464 struct status {
1465 list_entry_1st
1466 struct connection *c;
1467 struct cache_entry *ce;
1468 int state;
1469 int prev_error;
1470 int pri;
1471 void (*end)(struct status *, void *);
1472 void *data;
1473 struct remaining_info *prg;
1474 list_entry_last
1475 };
1476
1477 int is_noproxy_url(unsigned char *url);
1478 unsigned char *get_proxy_string(unsigned char *url);
1479 unsigned char *get_proxy(unsigned char *url);
1480 int is_proxy_url(unsigned char *url);
1481 unsigned char *remove_proxy_prefix(unsigned char *url);
1482 int get_allow_flags(unsigned char *url);
1483 int disallow_url(unsigned char *url, int allow_flags);
1484 void check_queue(void *dummy);
1485 unsigned long connect_info(int);
1486 void setcstate(struct connection *c, int);
1487 int get_keepalive_socket(struct connection *c, int *protocol_data);
1488 void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_data);
1489 int is_connection_restartable(struct connection *c);
1490 int is_last_try(struct connection *c);
1491 void retry_connection(struct connection *c);
1492 void abort_connection(struct connection *c);
1493 #define ALLOW_SMB 1
1494 #define ALLOW_FILE 2
1495 #define ALLOW_ALL (ALLOW_SMB | ALLOW_FILE)
1496 void load_url(unsigned char *, unsigned char *, struct status *, int, int, int, int, off_t);
1497 void change_connection(struct status *, struct status *, int);
1498 void detach_connection(struct status *, off_t, int, int);
1499 void abort_all_connections(void);
1500 int abort_background_connections(void);
1501 int is_entry_used(struct cache_entry *);
1502 void clear_connection_timeout(struct connection *);
1503 void set_connection_timeout(struct connection *);
1504 void set_connection_timeout_keepal(struct connection *);
1505 void add_blacklist_entry(unsigned char *, int);
1506 void del_blacklist_entry(unsigned char *, int);
1507 int get_blacklist_flags(unsigned char *);
1508 void free_blacklist(void);
1509
1510 #define BL_HTTP10 0x001
1511 #define BL_NO_ACCEPT_LANGUAGE 0x002
1512 #define BL_NO_CHARSET 0x004
1513 #define BL_NO_RANGE 0x008
1514 #define BL_NO_COMPRESSION 0x010
1515 #define BL_NO_BZIP2 0x020
1516 #define BL_IGNORE_CERTIFICATE 0x040
1517 #define BL_IGNORE_DOWNGRADE 0x080
1518 #define BL_IGNORE_CIPHER 0x100
1519 #define BL_AVOID_INSECURE 0x200
1520
1521 /* suffix.c */
1522
1523 int is_tld(unsigned char *name);
1524 int allow_cookie_domain(unsigned char *server, unsigned char *domain);
1525
1526 /* url.c */
1527
1528 struct session;
1529
1530 #define POST_CHAR 1
1531 #define POST_CHAR_STRING "\001"
1532
end_of_dir(unsigned char * url,unsigned char c)1533 static inline int end_of_dir(unsigned char *url, unsigned char c)
1534 {
1535 return c == POST_CHAR || c == '#' || ((c == ';' || c == '?') && (!url || !casecmp(url, (unsigned char *)"http", 4)));
1536 }
1537
1538 int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **);
1539 unsigned char *get_protocol_name(unsigned char *);
1540 unsigned char *get_host_name(unsigned char *);
1541 unsigned char *get_keepalive_id(unsigned char *);
1542 unsigned char *get_user_name(unsigned char *);
1543 unsigned char *get_pass(unsigned char *);
1544 int get_port(unsigned char *);
1545 unsigned char *get_port_str(unsigned char *);
1546 void (*get_protocol_handle(unsigned char *))(struct connection *);
1547 void (*get_external_protocol_function(unsigned char *))(struct session *, unsigned char *);
1548 int url_bypasses_socks(unsigned char *);
1549 unsigned char *get_url_data(unsigned char *);
1550 int url_non_ascii(unsigned char *url);
1551 unsigned char *join_urls(unsigned char *, unsigned char *);
1552 unsigned char *translate_url(unsigned char *, unsigned char *);
1553 unsigned char *extract_position(unsigned char *);
1554 int url_not_saveable(unsigned char *);
1555 void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special);
1556 void convert_file_charset(unsigned char **s, int *l, int start_l);
1557 unsigned char *idn_encode_host(unsigned char *host, int len, unsigned char *separator, int decode);
1558 unsigned char *idn_encode_url(unsigned char *url, int decode);
1559 unsigned char *display_url(struct terminal *term, unsigned char *url, int warn_idn);
1560 unsigned char *display_host(struct terminal *term, unsigned char *host);
1561 unsigned char *display_host_list(struct terminal *term, unsigned char *host);
1562
1563 /* connect.c */
1564
1565 struct read_buffer {
1566 int sock;
1567 int len;
1568 int close;
1569 void (*done)(struct connection *, struct read_buffer *);
1570 unsigned char data[1];
1571 };
1572
1573 #ifdef HAVE_SSL
1574 void clear_ssl_errors(int line);
1575 #endif
1576 int socket_and_bind(int pf, unsigned char *address);
1577 void close_socket(int *);
1578 void make_connection(struct connection *, int, int *, void (*)(struct connection *));
1579 void retry_connect(struct connection *, int, int);
1580 void continue_connection(struct connection *, int *, void (*)(struct connection *));
1581 int is_ipv6(int);
1582 int get_pasv_socket(struct connection *, int, int *, unsigned char *);
1583 #ifdef SUPPORT_IPV6
1584 int get_pasv_socket_ipv6(struct connection *, int, int *, unsigned char *);
1585 #endif
1586 void write_to_socket(struct connection *, int, unsigned char *, int, void (*)(struct connection *));
1587 struct read_buffer *alloc_read_buffer(struct connection *c);
1588 void read_from_socket(struct connection *, int, struct read_buffer *, void (*)(struct connection *, struct read_buffer *));
1589 void kill_buffer_data(struct read_buffer *, int);
1590
1591 /* cookies.c */
1592
1593 struct cookie {
1594 list_entry_1st
1595 unsigned char *name, *value;
1596 unsigned char *server;
1597 unsigned char *path, *domain;
1598 time_t created;
1599 time_t expires; /* zero means undefined */
1600 int secure;
1601 int saved_cookie;
1602 list_entry_last
1603 };
1604
1605 struct c_domain {
1606 list_entry_1st
1607 #ifdef REORDER_LIST_ENTRIES
1608 unsigned char pad;
1609 #endif
1610 list_entry_last
1611 unsigned char domain[1];
1612 };
1613
1614
1615 extern struct list_head all_cookies;
1616 extern struct list_head c_domains;
1617
1618 void set_cookie(unsigned char *, unsigned char *);
1619 void add_cookies(unsigned char **, int *, unsigned char *);
1620 void clear_cookies_file(void);
1621 void do_save_cookies(void);
1622 void init_cookies(void);
1623 unsigned long free_cookies(void);
1624 int is_in_domain(unsigned char *d, unsigned char *s);
1625 int is_path_prefix(unsigned char *d, unsigned char *s);
1626 int cookie_expired(struct cookie *c, time_t now);
1627 void free_cookie(struct cookie *c);
1628
1629 /* auth.c */
1630
1631 unsigned char *base64_encode(unsigned char *in, int inlen, unsigned char *prefix, unsigned char *suffix, int line_bits);
1632 unsigned char *get_auth_realm(unsigned char *url, unsigned char *head, int proxy);
1633 unsigned char *get_auth_string(unsigned char *url, int proxy);
1634 void free_auth(void);
1635 void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, unsigned char *password, int proxy);
1636 int find_auth(unsigned char *url, unsigned char *realm);
1637
1638 /* http.c */
1639
1640 int get_http_code(unsigned char *head, int *code, int *version);
1641 unsigned char *parse_http_header(unsigned char *, unsigned char *, unsigned char **);
1642 unsigned char *parse_header_param(unsigned char *, unsigned char *, int);
1643 time_t parse_http_date(unsigned char *);
1644 unsigned char *print_http_date(time_t);
1645 void http_func(struct connection *);
1646 void proxy_func(struct connection *);
1647
1648 /* https.c */
1649
1650 void https_func(struct connection *c);
1651 #ifdef HAVE_SSL
1652 extern int ssl_asked_for_password;
1653 void ssl_finish(void);
1654 links_ssl *getSSL(void);
1655 void freeSSL(links_ssl *);
1656 #ifdef HAVE_SSL_CERTIFICATES
1657 int verify_ssl_certificate(links_ssl *ssl, unsigned char *host);
1658 int verify_ssl_cipher(links_ssl *ssl);
1659 #define HAVE_BUILTIN_SSL_CERTIFICATES
1660 #endif
1661 int ssl_not_reusable(links_ssl *ssl);
1662 unsigned char *get_cipher_string(links_ssl *ssl);
1663 #endif
1664
1665 #if defined(HAVE_SSL) && defined(SSL_SESSION_RESUME)
1666 SSL_SESSION *get_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port);
1667 void retrieve_ssl_session(struct connection *c);
1668 unsigned long session_info(int type);
1669 void init_session_cache(void);
1670 #else
1671 #define init_session_cache() do { } while (0)
1672 #define retrieve_ssl_session(c) do { } while (0)
1673 #endif
1674
1675 /* data.c */
1676
1677 void data_func(struct connection *);
1678
1679 /* file.c */
1680
1681 void file_func(struct connection *);
1682
1683 /* finger.c */
1684
1685 void finger_func(struct connection *);
1686
1687 /* ftp.c */
1688
1689 #if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
1690 #define HAVE_IPTOS
1691 #endif
1692
1693 void ftp_func(struct connection *);
1694
1695 /* smb.c */
1696
1697 void smb_func(struct connection *);
1698
1699 /* mailto.c */
1700
1701 void magnet_func(struct session *, unsigned char *);
1702 void mailto_func(struct session *, unsigned char *);
1703 void telnet_func(struct session *, unsigned char *);
1704 void tn3270_func(struct session *, unsigned char *);
1705 void mms_func(struct session *, unsigned char *);
1706
1707 /* kbd.c */
1708
1709 #define BM_BUTT 15
1710 #define B_LEFT 0
1711 #define B_MIDDLE 1
1712 #define B_RIGHT 2
1713 #define B_FOURTH 3
1714 #define B_FIFTH 4
1715 #define B_SIXTH 5
1716 #define B_WHEELUP 8
1717 #define B_WHEELDOWN 9
1718 #define B_WHEELUP1 10
1719 #define B_WHEELDOWN1 11
1720 #define B_WHEELLEFT 12
1721 #define B_WHEELRIGHT 13
1722 #define B_WHEELLEFT1 14
1723 #define B_WHEELRIGHT1 15
1724 #define BM_IS_WHEEL(b) ((b) & 8)
1725
1726 #define BM_ACT 48
1727 #define B_DOWN 0
1728 #define B_UP 16
1729 #define B_DRAG 32
1730 #define B_MOVE 48
1731
1732 #define KBD_ENTER -0x100
1733 #define KBD_BS -0x101
1734 #define KBD_TAB -0x102
1735 #define KBD_ESC -0x103
1736 #define KBD_LEFT -0x104
1737 #define KBD_RIGHT -0x105
1738 #define KBD_UP -0x106
1739 #define KBD_DOWN -0x107
1740 #define KBD_INS -0x108
1741 #define KBD_DEL -0x109
1742 #define KBD_HOME -0x10a
1743 #define KBD_END -0x10b
1744 #define KBD_PAGE_UP -0x10c
1745 #define KBD_PAGE_DOWN -0x10d
1746 #define KBD_MENU -0x10e
1747 #define KBD_STOP -0x10f
1748
1749 #define KBD_F1 -0x120
1750 #define KBD_F2 -0x121
1751 #define KBD_F3 -0x122
1752 #define KBD_F4 -0x123
1753 #define KBD_F5 -0x124
1754 #define KBD_F6 -0x125
1755 #define KBD_F7 -0x126
1756 #define KBD_F8 -0x127
1757 #define KBD_F9 -0x128
1758 #define KBD_F10 -0x129
1759 #define KBD_F11 -0x12a
1760 #define KBD_F12 -0x12b
1761
1762 #define KBD_UNDO -0x140
1763 #define KBD_REDO -0x141
1764 #define KBD_FIND -0x142
1765 #define KBD_HELP -0x143
1766 #define KBD_COPY -0x144
1767 #define KBD_PASTE -0x145
1768 #define KBD_CUT -0x146
1769 #define KBD_PROPS -0x147
1770 #define KBD_FRONT -0x148
1771 #define KBD_OPEN -0x149
1772 #define KBD_BACK -0x14a
1773 #define KBD_FORWARD -0x14b
1774 #define KBD_RELOAD -0x14c
1775 #define KBD_BOOKMARKS -0x14d
1776 #define KBD_SELECT -0x14e
1777
1778 #define KBD_ESCAPE_MENU(x) ((x) <= KBD_F1 && (x) > KBD_CTRL_C)
1779
1780 #define KBD_CTRL_C -0x200
1781 #define KBD_CLOSE -0x201
1782
1783 #define KBD_SHIFT 1
1784 #define KBD_CTRL 2
1785 #define KBD_ALT 4
1786 #define KBD_PASTING 8
1787
1788 void handle_trm(int, int, int, int, int, void *, int);
1789 void free_all_itrms(void);
1790 void dispatch_special(unsigned char *);
1791 void kbd_ctrl_c(void);
1792 int is_blocked(void);
1793
1794 struct os2_key {
1795 int x, y;
1796 };
1797
1798 #if defined(OS2) || defined(DOS)
1799 extern struct os2_key os2xtd[256];
1800 #endif
1801
1802 struct itrm;
1803
1804 extern unsigned char init_seq[];
1805 extern unsigned char init_seq_x_mouse[];
1806 extern unsigned char init_seq_tw_mouse[];
1807 extern unsigned char init_set_xterm[];
1808 extern unsigned char term_seq[];
1809 extern unsigned char term_seq_x_mouse[];
1810 extern unsigned char term_seq_tw_mouse[];
1811 extern unsigned char term_seq_xterm[];
1812
1813 #if defined(GRDRV_SVGALIB) || defined(GRDRV_FB) || defined(GRDRV_GRX)
1814 #define GRDRV_VIRTUAL_DEVICES
1815 #endif
1816
1817 #ifdef GRDRV_VIRTUAL_DEVICES
1818 extern int kbd_set_raw;
1819 struct itrm *handle_svgalib_keyboard(void (*)(struct itrm *, unsigned char *, int));
1820 void svgalib_free_trm(struct itrm *);
1821 void svgalib_block_itrm(struct itrm *);
1822 int svgalib_unblock_itrm(struct itrm *);
1823 #endif
1824
1825
1826 struct rgb {
1827 unsigned char r, g, b; /* This is 3*8 bits with sRGB gamma (in sRGB space)
1828 * This is not rounded. */
1829 unsigned char pad;
1830 };
1831
1832 #ifdef G
1833
1834 /* lru.c */
1835
1836 struct lru_entry {
1837 struct lru_entry *above, *below, *next;
1838 struct lru_entry **previous;
1839 void *data;
1840 unsigned bytes_consumed;
1841 };
1842
1843 struct lru {
1844 int (*compare_function)(void *, void *);
1845 struct lru_entry *top, *bottom;
1846 my_uintptr_t bytes, items;
1847 };
1848
1849 void lru_insert(struct lru *cache, void *entry, struct lru_entry **row, unsigned bytes_consumed);
1850 void *lru_get_bottom(struct lru *cache);
1851 void lru_destroy_bottom(struct lru *cache);
1852 void lru_init(struct lru *cache, int (*compare_function)(void *entry, void *templ));
1853 void *lru_lookup(struct lru *cache, void *templ, struct lru_entry **row);
1854
1855 /* drivers.c */
1856
1857 /* Bitmap is allowed to pass only to that driver from which was obtained.
1858 * It is forbidden to get bitmap from svga driver and pass it to X driver.
1859 * It is impossible to get an error when registering a bitmap
1860 */
1861 struct bitmap {
1862 int x, y; /* Dimensions */
1863 ssize_t skip; /* Byte distance between vertically consecutive pixels */
1864 void *data; /* Pointer to room for topleft pixel */
1865 void *flags; /* Allocation flags for the driver */
1866 };
1867
1868 struct rect {
1869 int x1, x2, y1, y2;
1870 };
1871
1872 struct rect_set {
1873 int rl;
1874 int m;
1875 struct rect r[1];
1876 };
1877
1878 struct graphics_device {
1879 /* Only graphics driver is allowed to write to this */
1880
1881 struct rect size; /* Size of the window */
1882 /*int left, right, top, bottom;*/
1883 struct rect clip;
1884 /* right, bottom are coords of the first point that are outside the clipping area */
1885
1886 void *driver_data;
1887
1888 /* Only user is allowed to write here, driver inits to zero's */
1889 void *user_data;
1890 void (*redraw_handler)(struct graphics_device *dev, struct rect *r);
1891 void (*resize_handler)(struct graphics_device *dev);
1892 void (*keyboard_handler)(struct graphics_device *dev, int key, int flags);
1893 void (*mouse_handler)(struct graphics_device *dev, int x, int y, int buttons);
1894 void (*extra_handler)(struct graphics_device *dev, int type, unsigned char *string);
1895 };
1896
1897 struct driver_param;
1898
1899 struct graphics_driver {
1900 unsigned char *name;
1901 unsigned char *(*init_driver)(unsigned char *param, unsigned char *display); /* param is get from get_driver_param and saved into configure file */
1902
1903 /* Creates new device and returns pointer to it */
1904 struct graphics_device *(*init_device)(void);
1905
1906 /* Destroys the device */
1907 void (*shutdown_device)(struct graphics_device *dev);
1908
1909 void (*shutdown_driver)(void);
1910
1911 void (*emergency_shutdown)(void);
1912
1913 void (*after_fork)(void);
1914
1915 unsigned char *(*get_driver_param)(void); /* returns allocated string with parameter given to init_driver function */
1916 unsigned char *(*get_af_unix_name)(void);
1917
1918 void (*get_margin)(int *left, int *right, int *top, int *bottom);
1919 int (*set_margin)(int left, int right, int top, int bottom);
1920
1921 /* dest must have x and y filled in when get_empty_bitmap is called */
1922 int (*get_empty_bitmap)(struct bitmap *dest);
1923
1924 void (*register_bitmap)(struct bitmap *bmp);
1925
1926 void *(*prepare_strip)(struct bitmap *bmp, int top, int lines);
1927 void (*commit_strip)(struct bitmap *bmp, int top, int lines);
1928
1929 /* Must not touch x and y. Suitable for re-registering. */
1930 void (*unregister_bitmap)(struct bitmap *bmp);
1931 void (*draw_bitmap)(struct graphics_device *dev, struct bitmap *hndl, int x, int y);
1932
1933 /* Input into get_color has gamma 1/display_gamma.
1934 * Input of 255 means exactly the largest sample the display is able to produce.
1935 * Thus, if we have 3 bits for red, we will perform this code:
1936 * red=((red*7)+127)/255;
1937 */
1938 long (*get_color)(int rgb);
1939
1940 void (*fill_area)(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color);
1941 void (*draw_hline)(struct graphics_device *dev, int left, int y, int right, long color);
1942 void (*draw_vline)(struct graphics_device *dev, int x, int top, int bottom, long color);
1943 int (*scroll)(struct graphics_device *dev, struct rect_set **set, int scx, int scy);
1944 /* When scrolling, the empty spaces will have undefined contents. */
1945 /* returns:
1946 0 - the caller should not care about redrawing, redraw will be sent
1947 1 - the caller should redraw uncovered area */
1948 /* when set is not NULL rectangles in the set (uncovered area) should be redrawn */
1949 void (*set_clip_area)(struct graphics_device *dev);
1950
1951 void (*flush)(struct graphics_device *dev);
1952
1953 int (*block)(struct graphics_device *dev); /* restore old videomode and disable drawing on terminal */
1954 int (*unblock)(struct graphics_device *dev); /* reenable the terminal (return -1 if failed) */
1955
1956 void (*set_palette)(void);
1957 unsigned short *(*get_real_colors)(void);
1958
1959 void (*set_title)(struct graphics_device *dev, unsigned char *title);
1960 /* set window title. title is in utf-8 encoding -- you should recode it to device charset */
1961 /* if device doesn't support titles (svgalib, framebuffer), this should be NULL, not empty function ! */
1962
1963 int (*exec)(unsigned char *command, int flag);
1964 /* -if !NULL executes command on this graphics device,
1965 -if NULL links uses generic (console) command executing
1966 functions
1967 -return value is the same as of the 'system' syscall
1968 -if flag is !0, run command in separate shell
1969 else run command directly
1970 */
1971
1972 void (*set_clipboard_text)(unsigned char *text);
1973 unsigned char *(*get_clipboard_text)(void);
1974
1975 int depth; /* Data layout
1976 * depth
1977 * 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
1978 * +---------+-+-+---------+-----+
1979 * + | | | | |
1980 * +---------+-+-+---------+-----+
1981 *
1982 * 0 - 2 Number of bytes per pixel in passed bitmaps
1983 * 3 - 7 Number of significant bits per pixel -- 1, 4, 8, 15, 16, 24
1984 * 8 0 -- normal order, 1 -- misordered.Has the same value as vga_misordered from the VGA mode.
1985 * 9 1 -- misordered (0rgb)
1986 * 10 - 14 1 -- dither to the requested number of bits
1987 *
1988 * This number is to be used by the layer that generates images.
1989 * Memory layout for 1 bytes per pixel is:
1990 * 2 colors:
1991 * 7 6 5 4 3 2 1 0
1992 * +-------------+-+
1993 * | 0 |B| B is The Bit. 0 black, 1 white
1994 * +-------------+-+
1995 *
1996 * 16 colors:
1997 * 7 6 5 4 3 2 1 0
1998 * +-------+-------+
1999 * | 0 | PIXEL | Pixel is 4-bit index into palette
2000 * +-------+-------+
2001 *
2002 * 256 colors:
2003 * 7 6 5 4 3 2 1 0
2004 * +---------------+
2005 * | --PIXEL-- | Pixels is 8-bit index into palette
2006 * +---------------+
2007 */
2008 int x, y; /* size of screen. only for drivers that use virtual devices */
2009 int flags; /* GD_xxx flags */
2010 struct driver_param *param;
2011 };
2012
2013 #define GD_DONT_USE_SCROLL 1
2014 #define GD_NEED_CODEPAGE 2
2015 #define GD_UNICODE_KEYS 4
2016 #define GD_ONLY_1_WINDOW 8
2017 #define GD_NOAUTO 16
2018 #define GD_NO_OS_SHELL 32
2019 #define GD_NO_LIBEVENT 64
2020 #define GD_SELECT_PALETTE 128
2021 #define GD_SWITCH_PALETTE 256
2022
2023 extern struct graphics_driver *drv;
2024
2025 #define CLIP_DRAW_BITMAP \
2026 if (!is_rect_valid(&dev->clip)) return; \
2027 if (!bmp->x || !bmp->y) return; \
2028 if (x >= dev->clip.x2) return; \
2029 if (x + bmp->x <= dev->clip.x1) return; \
2030 if (y >= dev->clip.y2) return; \
2031 if (y + bmp->y <= dev->clip.y1) return; \
2032
2033 #define CLIP_FILL_AREA \
2034 if (x1 < dev->clip.x1) x1 = dev->clip.x1; \
2035 if (x2 > dev->clip.x2) x2 = dev->clip.x2; \
2036 if (y1 < dev->clip.y1) y1 = dev->clip.y1; \
2037 if (y2 > dev->clip.y2) y2 = dev->clip.y2; \
2038 if (x1 >= x2 || y1 >= y2) return; \
2039
2040 #define CLIP_DRAW_HLINE \
2041 if (y < dev->clip.y1) return; \
2042 if (y >= dev->clip.y2) return; \
2043 if (x1 < dev->clip.x1) x1 = dev->clip.x1; \
2044 if (x2 > dev->clip.x2) x2 = dev->clip.x2; \
2045 if (x1 >= x2) return; \
2046
2047 #define CLIP_DRAW_VLINE \
2048 if (x < dev->clip.x1) return; \
2049 if (x >= dev->clip.x2) return; \
2050 if (y1 < dev->clip.y1) y1 = dev->clip.y1; \
2051 if (y2 > dev->clip.y2) y2 = dev->clip.y2; \
2052 if (y1 >= y2) return; \
2053
2054 void add_graphics_drivers(unsigned char **s, int *l);
2055 unsigned char *init_graphics(unsigned char *, unsigned char *, unsigned char *);
2056 void shutdown_graphics(void);
2057 void update_driver_param(void);
2058 int g_kbd_codepage(struct graphics_driver *drv);
2059
2060 extern struct graphics_device **virtual_devices;
2061 extern int n_virtual_devices;
2062 extern struct graphics_device *current_virtual_device;
2063
is_rect_valid(struct rect * r)2064 static inline int is_rect_valid(struct rect *r)
2065 {
2066 return r->x1 < r->x2 && r->y1 < r->y2;
2067 }
2068 int do_rects_intersect(struct rect *, struct rect *);
2069 void intersect_rect(struct rect *, struct rect *, struct rect *);
2070 void unite_rect(struct rect *, struct rect *, struct rect *);
2071
2072 struct rect_set *init_rect_set(void);
2073 void add_to_rect_set(struct rect_set **, struct rect *);
2074 void exclude_rect_from_set(struct rect_set **, struct rect *);
exclude_from_set(struct rect_set ** s,int x1,int y1,int x2,int y2)2075 static inline void exclude_from_set(struct rect_set **s, int x1, int y1, int x2, int y2)
2076 {
2077 struct rect r;
2078 r.x1 = x1, r.x2 = x2, r.y1 = y1, r.y2 = y2;
2079 exclude_rect_from_set(s, &r);
2080 }
2081
2082 void set_clip_area(struct graphics_device *dev, struct rect *r);
2083 int restrict_clip_area(struct graphics_device *dev, struct rect *r, int x1, int y1, int x2, int y2);
2084
2085 struct rect_set *g_scroll(struct graphics_device *dev, int scx, int scy);
2086
2087 #ifdef GRDRV_VIRTUAL_DEVICES
2088 void init_virtual_devices(struct graphics_driver *, int);
2089 struct graphics_device *init_virtual_device(void);
2090 #define VD_NEXT -1
2091 void switch_virtual_device(int);
2092 void shutdown_virtual_device(struct graphics_device *dev);
2093 void resize_virtual_devices(int x, int y);
2094 void shutdown_virtual_devices(void);
2095 #endif
2096
2097 #if defined(GRDRV_X) || defined(GRDRV_HAIKU)
2098 int x_exec(unsigned char *command, int fg);
2099 #endif
2100
2101 /* dip.c */
2102
2103 /* Digital Image Processing utilities
2104 * (c) 2000 Clock <clock@atrey.karlin.mff.cuni.cz>
2105 *
2106 * This file is a part of Links
2107 *
2108 * This file does gray scaling (for prescaling fonts), color scaling (for scaling images
2109 * where different size is defined in the HTML), two colors mixing (alpha monochromatic letter
2110 * on a monochromatic backround and font operations.
2111 */
2112
2113 #if !SIZEOF_UNSIGNED_SHORT || SIZEOF_UNSIGNED_SHORT > 2
2114 #define limit_16(x) ((x) >= 0xffff ? 0xffff : (x))
2115 #define cmd_limit_16(x) do { if ((x) >= 0xffff) (x) = 0xffff; } while (0)
2116 #else
2117 #define limit_16(x) (x)
2118 #define cmd_limit_16(x) do { } while (0)
2119 #endif
2120
2121 #define sRGB_gamma 0.45455 /* For HTML, which runs
2122 * according to sRGB standard. Number
2123 * in HTML tag is linear to photons raised
2124 * to this power.
2125 */
2126
2127 extern unsigned aspect; /* Must hold at least 20 bits */
2128 my_uintptr_t fontcache_info(int type);
2129
2130 #define G_BFU_FONT_SIZE menu_font_size
2131
2132 struct letter {
2133 const unsigned char *begin; /* Begin in the byte stream (of PNG data) */
2134 int length; /* Length (in bytes) of the PNG data in the byte stream */
2135 int code; /* Unicode code of the character */
2136 short xsize; /* x size of the PNG image */
2137 short ysize; /* y size of the PNG image */
2138 struct lru_entry *color_list;
2139 };
2140
2141 struct font {
2142 int begin; /* Begin in the letter stream */
2143 int length; /* Length in the letter stream */
2144 };
2145
2146 #ifdef HAVE_FREETYPE
2147 struct freetype_face;
2148 #endif
2149
2150 struct style {
2151 int refcount;
2152 unsigned char r0, g0, b0, r1, g1, b1;
2153 /* ?0 are background, ?1 foreground.
2154 * These are unrounded 8-bit sRGB space
2155 */
2156 unsigned char flags; /* non-zero means underline */
2157 int height;
2158 long underline_color; /* Valid only if flags are nonzero */
2159 int mono_space; /* -1 if the font is not monospaced
2160 * width of the space otherwise
2161 */
2162 int mono_height; /* Height of the space if mono_space is >=0
2163 * undefined otherwise
2164 */
2165 #ifdef HAVE_FREETYPE
2166 struct freetype_face *ft_face;
2167 #endif
2168 };
2169
2170 struct font_cache_entry {
2171 unsigned char r0, g0, b0, r1, g1, b1;
2172 unsigned char flags;
2173 int char_number;
2174 int mono_space, mono_height; /* if the letter was rendered for a
2175 monospace font, then size of the space. Otherwise, mono_space
2176 is -1 and mono_height is undefined. */
2177 #ifdef HAVE_FREETYPE
2178 unsigned char *font;
2179 #endif
2180 struct bitmap bitmap;
2181 };
2182
2183
2184 struct cached_image;
2185
2186 int compute_width(int ix, int iy, int required_length);
2187 void g_print_text(struct graphics_device *device, int x, int y, struct style *style, unsigned char *text, int *width);
2188 int g_text_width(struct style *style, unsigned char *text);
2189 int g_char_width(struct style *style, unsigned ch);
2190 /*unsigned char ags_8_to_8(unsigned char input, float gamma);*/
2191 unsigned short ags_8_to_16(unsigned char input, float gamma);
2192 unsigned char ags_16_to_8(unsigned short input, float gamma);
2193 unsigned short ags_16_to_16(unsigned short input, float gamma);
2194 void agx_24_to_48(unsigned short *my_restrict dest, const unsigned char *my_restrict src,
2195 size_t length, float red_gamma, float green_gamma, float blue_gamma);
2196 void make_gamma_table(struct cached_image *cimg);
2197 void agx_24_to_48_table(unsigned short *my_restrict dest, const unsigned char *my_restrict src,
2198 size_t length, unsigned short *my_restrict gamma_table);
2199 void agx_48_to_48_table(unsigned short *my_restrict dest,
2200 const unsigned short *my_restrict src, size_t length, unsigned short *my_restrict table);
2201 void agx_48_to_48(unsigned short *my_restrict dest,
2202 const unsigned short *my_restrict src, size_t length, float red_gamma,
2203 float green_gamma, float blue_gamma);
2204 void agx_and_uc_32_to_48_table(unsigned short *my_restrict dest,
2205 const unsigned char *my_restrict src, size_t length, unsigned short *my_restrict table,
2206 unsigned short rb, unsigned short gb, unsigned short bb);
2207 void agx_and_uc_32_to_48(unsigned short *my_restrict dest,
2208 const unsigned char *my_restrict src, size_t length, float red_gamma,
2209 float green_gamma, float blue_gamma, unsigned short rb, unsigned
2210 short gb, unsigned short bb);
2211 void agx_and_uc_64_to_48_table(unsigned short *my_restrict dest,
2212 const unsigned short *my_restrict src, size_t length, unsigned short *my_restrict gamma_table,
2213 unsigned short rb, unsigned short gb, unsigned short bb);
2214 void agx_and_uc_64_to_48(unsigned short *my_restrict dest,
2215 const unsigned short *my_restrict src, size_t length, float red_gamma,
2216 float green_gamma, float blue_gamma, unsigned short rb, unsigned
2217 short gb, unsigned short bb);
2218 void mix_one_color_48(unsigned short *my_restrict dest, size_t length,
2219 unsigned short r, unsigned short g, unsigned short b);
2220 void mix_one_color_24(unsigned char *my_restrict dest, size_t length,
2221 unsigned char r, unsigned char g, unsigned char b);
2222 void scale_color(unsigned short *in, size_t ix, size_t iy, unsigned short **out,
2223 size_t ox, size_t oy);
2224 void update_aspect(void);
2225 void flush_bitmaps(int flush_font, int flush_images, int redraw_all);
2226
2227 struct g_object;
2228
2229 struct wrap_struct {
2230 struct style *style;
2231 unsigned char *text;
2232 int pos;
2233 int width;
2234 struct g_object *obj;
2235 struct g_object *last_wrap_obj;
2236 unsigned char *last_wrap;
2237 int force_break;
2238 };
2239
2240 int g_wrap_text(struct wrap_struct *);
2241
2242 int hack_rgb(int rgb);
2243
2244 #define FF_BOLD 1
2245 #define FF_MONOSPACED 2
2246 #define FF_ITALIC 4
2247 #define FF_UNDERLINE 8
2248
2249 #ifndef USE_ITALIC
2250 #define FF_SHAPES 4
2251 #else
2252 #define FF_SHAPES 8
2253 #endif
2254
2255 struct style *g_get_style_font(int fg, int bg, int size, int fflags, unsigned char *font);
2256 struct style *g_get_style(int fg, int bg, int size, int fflags);
2257 struct style *g_invert_style(struct style *);
2258 void g_free_style(struct style *style0);
2259 struct style *g_clone_style(struct style *);
2260
2261 extern tcount gamma_stamp;
2262
2263 extern long gamma_cache_color_1;
2264 extern int gamma_cache_rgb_1;
2265 extern long gamma_cache_color_2;
2266 extern int gamma_cache_rgb_2;
2267
2268 long real_dip_get_color_sRGB(int rgb);
2269
dip_get_color_sRGB(int rgb)2270 static inline long dip_get_color_sRGB(int rgb)
2271 {
2272 if (rgb == gamma_cache_rgb_1) return gamma_cache_color_1;
2273 if (rgb == gamma_cache_rgb_2) return gamma_cache_color_2;
2274 return real_dip_get_color_sRGB(rgb);
2275 }
2276
2277 void init_dip(void);
2278 void get_links_icon(unsigned char **data, int *width, int *height, ssize_t *skip, int pad);
2279
2280 #ifdef PNG_USER_MEM_SUPPORTED
2281 void *my_png_alloc(png_structp png_ptr, png_size_t size);
2282 void my_png_free(png_structp png_ptr, void *ptr);
2283 #endif
2284
2285 /* dither.c */
2286
2287 extern int slow_fpu; /* -1 --- don't know, 0 --- no, 1 --- yes */
2288
2289 /* Dithering functions (for blocks of pixels being dithered into bitmaps) */
2290 void dither(unsigned short *in, struct bitmap *out);
2291 int *dither_start(unsigned short *in, struct bitmap *out);
2292 void dither_restart(unsigned short *in, struct bitmap *out, int *dregs);
2293 extern void (*round_fn)(unsigned short *my_restrict in, struct bitmap *out);
2294
2295 long (*get_color_fn(int depth))(int rgb);
2296 void init_dither(int depth);
2297 void round_color_sRGB_to_48(unsigned short *my_restrict red, unsigned short *my_restrict green,
2298 unsigned short *my_restrict blue, int rgb);
2299
2300 void q_palette(unsigned size, unsigned color, unsigned scale, unsigned rgb[3]);
2301 double rgb_distance(int r1, int g1, int b1, int r2, int g2, int b2);
2302
2303 void free_dither(void);
2304
2305 /* freetype.c */
2306
2307 #ifdef HAVE_FREETYPE
2308
2309 struct freetype_face *freetype_flags_to_face(int fflags);
2310
2311 #define sizeof_freetype_cache 1024
2312 extern struct lru_entry **freetype_cache;
2313
2314 int freetype_load_metric_cached(struct style *st, int char_number, int *xp, int y);
2315 int freetype_type_character(struct style *st, int char_number, unsigned char **dest, int *x, int y);
2316
2317 struct freetype_face *freetype_get_font(unsigned char *path);
2318 void freetype_free_font(struct freetype_face *face);
2319 unsigned char *freetype_get_allocated_font_name(struct style *st);
2320
2321 void freetype_reload(void);
2322 void freetype_init(void);
2323 void freetype_done(void);
2324
2325 void add_freetype_version(unsigned char **s, int *l);
2326
2327 /* fontconf.c */
2328
2329 struct list_of_fonts {
2330 unsigned char *name;
2331 unsigned char *file;
2332 };
2333
2334 void fontconfig_list_fonts(struct list_of_fonts **fonts, int *n_fonts, int monospaced);
2335 void fontconfig_free_fonts(struct list_of_fonts *fonts);
2336 void wait_for_fontconfig(void);
2337 void fontconfig_init(void);
2338
2339 void add_fontconfig_version(unsigned char **s, int *l);
2340
2341 #else
2342
freetype_reload(void)2343 static inline void freetype_reload(void) { }
freetype_init(void)2344 static inline void freetype_init(void) { }
freetype_done(void)2345 static inline void freetype_done(void) { }
2346
fontconfig_init(void)2347 static inline void fontconfig_init(void) { }
fontconfig_done(void)2348 static inline void fontconfig_done(void) { }
2349
2350 #endif
2351
2352 #endif
2353
2354 /* terminal.c */
2355
2356 extern unsigned char frame_dumb[];
2357
2358 #ifndef ENABLE_UTF8
2359 typedef unsigned char char_t;
2360 #else
2361 typedef unsigned char_t;
2362 #endif
2363
2364 typedef struct {
2365 char_t ch
2366 #ifdef ENABLE_UTF8
2367 :24
2368 #endif
2369 ;
2370 unsigned char at;
2371 } chr;
2372
2373 #ifdef ENABLE_UTF8
2374 #define chr_has_padding (sizeof(chr) != 4 || value_0())
2375 #else
2376 #define chr_has_padding (sizeof(chr) != 2 || value_0())
2377 #endif
2378
2379 struct links_event {
2380 int ev;
2381 int x;
2382 int y;
2383 my_intptr_t b;
2384 };
2385
2386 #define EV_INIT 0
2387 #define EV_KBD 1
2388 #define EV_MOUSE 2
2389 #define EV_EXTRA 3
2390 #define EV_REDRAW 4
2391 #define EV_RESIZE 5
2392 #define EV_ABORT 6
2393
2394 #define EV_EXTRA_OPEN_URL 0
2395
2396 #define EVH_NOT_PROCESSED 0
2397 #define EVH_LINK_KEYDOWN_PROCESSED 1
2398 #define EVH_LINK_KEYPRESS_PROCESSED 2
2399 #define EVH_DOCUMENT_KEYDOWN_PROCESSED 3
2400 #define EVH_DOCUMENT_KEYPRESS_PROCESSED 4
2401
2402 struct window {
2403 list_entry_1st
2404 void (*handler)(struct window *, struct links_event *, int fwd);
2405 void *data;
2406 int xp, yp;
2407 struct terminal *term;
2408 #ifdef G
2409 struct rect pos;
2410 struct rect redr;
2411 #endif
2412 list_entry_last
2413 };
2414
2415 #define MAX_TERM_LEN 32 /* this must be multiple of 8! (alignment problems) */
2416
2417 #define MAX_CWD_LEN 4096 /* this must be multiple of 8! (alignment problems) */
2418
2419 #define ENV_XWIN 1
2420 #define ENV_SCREEN 2
2421 #define ENV_OS2VIO 4
2422 #define ENV_BE 8
2423 #define ENV_TWIN 16
2424 #define ENV_WIN32 32
2425 #define ENV_INTERIX 64
2426 #define ENV_G 32768
2427
2428 struct term_spec;
2429
2430 struct terminal {
2431 list_entry_1st
2432 tcount count;
2433
2434 int x;
2435 int y;
2436 /* text only */
2437 int master;
2438 int fdin;
2439 int fdout;
2440 int environment;
2441 unsigned char term[MAX_TERM_LEN];
2442 unsigned char cwd[MAX_CWD_LEN];
2443 chr *screen;
2444 chr *last_screen;
2445 struct term_spec *spec;
2446 int default_character_set;
2447 int cx;
2448 int cy;
2449 int lcx;
2450 int lcy;
2451 int dirty;
2452 int redrawing;
2453 int blocked;
2454 unsigned char *input_queue;
2455 int qlen;
2456 int real_x;
2457 int real_y;
2458 int left_margin;
2459 int top_margin;
2460 /* end-of text only */
2461
2462 struct list_head windows;
2463 unsigned char *title;
2464
2465 int handle_to_close;
2466 #ifdef G
2467 struct graphics_device *dev;
2468 int last_mouse_x;
2469 int last_mouse_y;
2470 int last_mouse_b;
2471 #endif
2472 #if defined(G) || defined(ENABLE_UTF8)
2473 unsigned char utf8_buffer[7];
2474 int utf8_paste_mode;
2475 #endif
2476 list_entry_last
2477 };
2478
2479 struct term_spec {
2480 list_entry_1st
2481 unsigned char term[MAX_TERM_LEN];
2482 int mode;
2483 int m11_hack;
2484 int restrict_852;
2485 int block_cursor;
2486 int col;
2487 int braille;
2488 int character_set;
2489 int left_margin;
2490 int right_margin;
2491 int top_margin;
2492 int bottom_margin;
2493 list_entry_last
2494 };
2495
2496 #define TERM_DUMB 0
2497 #define TERM_VT100 1
2498 #define TERM_LINUX 2
2499 #define TERM_KOI8 3
2500 #define TERM_FREEBSD 4
2501 #define TERM_UTF8 5
2502
2503 #define ATTR_FRAME 0x80
2504
2505 extern struct list_head term_specs;
2506 extern struct list_head terminals;
2507
term_charset(struct terminal * term)2508 static inline int term_charset(struct terminal *term)
2509 {
2510 if (term->spec->character_set >= 0)
2511 return term->spec->character_set;
2512 return term->default_character_set;
2513 }
2514
2515 int hard_write(int, const unsigned char *, int);
2516 int hard_read(int, unsigned char *, int);
2517 unsigned char *get_cwd(void);
2518 void set_cwd(unsigned char *);
2519 unsigned char get_attribute(int, int);
2520 struct terminal *init_term(int, int, void (*)(struct window *, struct links_event *, int));
2521 #ifdef G
2522 struct terminal *init_gfx_term(void (*)(struct window *, struct links_event *, int), unsigned char *, void *, int);
2523 #endif
2524 struct term_spec *new_term_spec(unsigned char *);
2525 void free_term_specs(void);
2526 void destroy_terminal(void *);
2527 void cls_redraw_all_terminals(void);
2528 void redraw_below_window(struct window *);
2529 void add_window(struct terminal *, void (*)(struct window *, struct links_event *, int), void *);
2530 void delete_window(struct window *);
2531 void delete_window_ev(struct window *, struct links_event *ev);
2532 void set_window_ptr(struct window *, int, int);
2533 void get_parent_ptr(struct window *, int *, int *);
2534 void add_empty_window(struct terminal *, void (*)(void *), void *);
2535 void draw_to_window(struct window *, void (*)(struct terminal *, void *), void *);
2536 void redraw_window(struct window *);
2537 void redraw_all_terminals(void);
2538 void flush_terminal(struct terminal *);
2539
2540 #ifdef G
2541
2542 void set_window_pos(struct window *, int, int, int, int);
2543 void t_redraw(struct graphics_device *, struct rect *);
2544
2545 #endif
2546
2547 /* text only */
2548 void set_char(struct terminal *, int, int, unsigned, unsigned char);
2549 const chr *get_char(struct terminal *, int, int);
2550 void set_color(struct terminal *, int, int, unsigned char);
2551 void set_only_char(struct terminal *, int, int, unsigned, unsigned char);
2552 void set_line(struct terminal *, int, int, int, chr *);
2553 void set_line_color(struct terminal *, int, int, int, unsigned char);
2554 void fill_area(struct terminal *, int, int, int, int, unsigned, unsigned char);
2555 void draw_frame(struct terminal *, int, int, int, int, unsigned char, int);
2556 void print_text(struct terminal *, int, int, int, unsigned char *, unsigned char);
2557 void set_cursor(struct terminal *, int, int, int, int);
2558
2559 void destroy_all_terminals(void);
2560 void block_itrm(int);
2561 int unblock_itrm(int);
2562 void exec_thread(void *, int);
2563 void close_handle(void *);
2564
2565 #define TERM_FN_TITLE 1
2566 #define TERM_FN_RESIZE 2
2567
2568 #ifdef G
2569 int have_extra_exec(void);
2570 #endif
2571 void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, unsigned char);
2572 void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
2573 void set_terminal_title(struct terminal *, unsigned char *);
2574 struct terminal *find_terminal(tcount count);
2575
2576 /* language.c */
2577
2578 #include "language.h"
2579
2580 extern unsigned char dummyarray[];
2581
2582 extern int current_language;
2583
2584 void init_trans(void);
2585 void shutdown_trans(void);
2586 #if defined(OS2) || defined(DOS)
2587 int get_country_language(int c);
2588 #endif
2589 int get_language_from_lang(unsigned char *);
2590 int get_default_language(void);
2591 int get_current_language(void);
2592 int get_default_charset(void);
2593 int get_commandline_charset(void);
2594 unsigned char *get_text_translation(unsigned char *, struct terminal *term);
2595 unsigned char *get_english_translation(unsigned char *);
2596 int n_languages(void);
2597 unsigned char *language_name(int);
2598 void set_language(int);
2599 unsigned char *strerror_alloc(int err, struct terminal *term);
2600
2601 #define TEXT_(x) (dummyarray + x) /* TEXT causes name clash on windows */
2602
2603 /* dos.c */
2604
2605 #ifdef DOS
2606 void dos_poll_break(void);
2607 void dos_mouse_terminate(void);
2608 void dos_save_screen(void);
2609 void dos_restore_screen(void);
2610 int dos_is_bw(void);
2611 #else
2612 #define dos_poll_break() do { } while (0)
2613 #endif
2614
2615 /* grx.c */
2616
2617 #ifdef GRDRV_GRX
2618 extern int grx_mouse_initialized;
2619 void grx_mouse_poll(void);
2620 int grx_mouse_event(void);
2621 #endif
2622
2623 /* af_unix.c */
2624
2625 extern int s_unix_fd;
2626 int bind_to_af_unix(unsigned char *name);
2627 void af_unix_close(void);
2628
2629 /* main.c */
2630
2631 extern int terminal_pipe[2];
2632
2633 extern int retval;
2634
2635 extern unsigned char *path_to_exe;
2636 extern char **g_argv;
2637 extern int g_argc;
2638
2639 void sig_tstp(void *t);
2640 void sig_cont(void *t);
2641
2642 void unhandle_terminal_signals(struct terminal *term);
2643 int attach_terminal(int, int, int, void *, int);
2644 #ifdef G
2645 int attach_g_terminal(unsigned char *, void *, int);
2646 void gfx_connection(int);
2647 #endif
2648
2649 /* objreq.c */
2650
2651 #define O_WAITING 0
2652 #define O_LOADING 1
2653 #define O_FAILED -1
2654 #define O_INCOMPLETE -2
2655 #define O_OK -3
2656
2657 struct object_request {
2658 list_entry_1st
2659 int refcount;
2660 tcount count;
2661 tcount term;
2662 struct status stat;
2663 struct cache_entry *ce_internal;
2664 struct cache_entry *ce;
2665 unsigned char *orig_url;
2666 unsigned char *url;
2667 unsigned char *prev_url; /* allocated string with referrer or NULL */
2668 unsigned char *goto_position;
2669 int pri;
2670 int cache;
2671 void (*upcall)(struct object_request *, void *);
2672 void *data;
2673 int redirect_cnt;
2674 int state;
2675 #define HOLD_AUTH 1
2676 #define HOLD_CERT 2
2677 int hold;
2678 int dont_print_error;
2679 struct timer *timer;
2680
2681 off_t last_bytes;
2682
2683 uttime last_update;
2684 list_entry_last
2685 };
2686
2687 void request_object(struct terminal *, unsigned char *, unsigned char *, int, int, int, void (*)(struct object_request *, void *), void *, struct object_request **);
2688 void clone_object(struct object_request *, struct object_request **);
2689 void release_object(struct object_request **);
2690 void release_object_get_stat(struct object_request **, struct status *, int);
2691 void detach_object_connection(struct object_request *, off_t);
2692
2693 /* compress.c */
2694
2695 #if defined(HAVE_ZLIB) || defined(HAVE_BROTLI) || defined(HAVE_BZIP2) || defined(HAVE_LZMA) || defined(HAVE_LZIP)
2696 #define HAVE_ANY_COMPRESSION
2697 #endif
2698
2699 extern my_uintptr_t decompressed_cache_size;
2700
2701 int get_file_by_term(struct terminal *term, struct cache_entry *ce, unsigned char **start, size_t *len, int *errp);
2702 int get_file(struct object_request *o, unsigned char **start, size_t *len);
2703 void free_decompressed_data(struct cache_entry *e);
2704 void add_compress_methods(unsigned char **s, int *l);
2705
2706 /* session.c */
2707
2708 struct link_def {
2709 unsigned char *link;
2710 unsigned char *target;
2711
2712 unsigned char *label; /* only for image maps */
2713 unsigned char *shape;
2714 unsigned char *coords;
2715
2716 unsigned char *onclick;
2717 unsigned char *ondblclick;
2718 unsigned char *onmousedown;
2719 unsigned char *onmouseup;
2720 unsigned char *onmouseover;
2721 unsigned char *onmouseout;
2722 unsigned char *onmousemove;
2723 };
2724
2725 struct compressed_chars {
2726 list_entry_1st
2727 int total_len;
2728 int cpos;
2729 list_entry_last
2730 unsigned char chars[1];
2731 };
2732
2733 struct line {
2734 int l;
2735 int allocated;
2736 union {
2737 chr *du;
2738 unsigned char *dc;
2739 } u;
2740 };
2741
2742 struct point {
2743 int x;
2744 int y;
2745 };
2746
2747 struct form {
2748 unsigned char *action;
2749 unsigned char *target;
2750 unsigned char *form_name;
2751 unsigned char *onsubmit;
2752 int method;
2753 int num;
2754 };
2755
2756 #define FM_GET 0
2757 #define FM_POST 1
2758 #define FM_POST_MP 2
2759
2760 #define FC_TEXT 1
2761 #define FC_PASSWORD 2
2762 #define FC_FILE_UPLOAD 3
2763 #define FC_TEXTAREA 4
2764 #define FC_CHECKBOX 5
2765 #define FC_RADIO 6
2766 #define FC_SELECT 7
2767 #define FC_SUBMIT 8
2768 #define FC_IMAGE 9
2769 #define FC_RESET 10
2770 #define FC_HIDDEN 11
2771 #define FC_BUTTON 12
2772
2773 struct menu_item;
2774
2775 struct form_control {
2776 list_entry_1st
2777 int form_num; /* cislo formulare */
2778 int ctrl_num; /* identifikace polozky v ramci formulare */
2779 int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v poli form_info) */
2780 int position;
2781 int method;
2782 unsigned char *action;
2783 unsigned char *target;
2784 unsigned char *onsubmit; /* script to be executed on submit */
2785 int type;
2786 unsigned char *name;
2787 unsigned char *form_name;
2788 unsigned char *alt;
2789 int ro;
2790 unsigned char *default_value;
2791 int default_state;
2792 int size;
2793 int cols, rows, wrap;
2794 int maxlength;
2795 int nvalues; /* number of values in a select item */
2796 unsigned char **values; /* values of a select item */
2797 unsigned char **labels; /* labels (shown text) of a select item */
2798 struct menu_item *menu;
2799 list_entry_last
2800 };
2801
2802 struct line_info {
2803 int st_offs;
2804 int en_offs;
2805 int chars;
2806 };
2807
2808 struct format_text_cache_entry {
2809 int width;
2810 int wrap;
2811 int cp;
2812 int last_state;
2813 int last_vpos;
2814 int last_vypos;
2815 int last_cursor;
2816 int n_lines;
2817 struct line_info ln[1];
2818 };
2819
2820 struct form_state {
2821 int form_num; /* cislo formulare */
2822 int ctrl_num; /* identifikace polozky v ramci formulare */
2823 int g_ctrl_num; /* identifikace polozky mezi vsemi polozkami (poradi v poli form_info) */
2824 int position;
2825 int type;
2826 unsigned char *string; /* selected value of a select item */
2827 int state; /* index of selected item of a select item */
2828 int vpos;
2829 int vypos;
2830 struct format_text_cache_entry *ftce;
2831 #ifdef JS
2832 int changed; /* flag if form element has changed --- for onchange handler */
2833 #endif
2834 };
2835
2836 struct js_event_spec;
2837
2838 struct link {
2839 int type; /* one of L_XXX constants */
2840 int num; /* link number (used when user turns on link numbering) */
2841 unsigned char *where; /* URL of the link */
2842 unsigned char *target; /* name of target frame where to open the link */
2843 unsigned char *where_img; /* URL of image (if any) */
2844 unsigned char *img_alt; /* alt of image (if any) - valid only when link is an image */
2845 struct form_control *form; /* form info, usually NULL */
2846 unsigned sel_color; /* link color */
2847 int n; /* number of points */
2848 int first_point_to_move;
2849 struct point *pos;
2850 struct js_event_spec *js_event;
2851 int obj_order;
2852 #ifdef G
2853 struct rect r;
2854 struct g_object *obj;
2855 #endif
2856 };
2857
2858 #define L_LINK 0
2859 #define L_BUTTON 1
2860 #define L_CHECKBOX 2
2861 #define L_SELECT 3
2862 #define L_FIELD 4
2863 #define L_AREA 5
2864
2865 struct link_bg {
2866 int x, y;
2867 unsigned char c;
2868 };
2869
2870 struct tag {
2871 list_entry_1st
2872 int x;
2873 int y;
2874 list_entry_last
2875 unsigned char name[1];
2876 };
2877
2878 extern struct rgb palette_16_colors[16];
2879
2880 /* when you add anything, don't forget to initialize it in default.c on line:
2881 * struct document_setup dds = { ... };
2882 */
2883 struct document_setup {
2884 int assume_cp;
2885 int hard_assume;
2886 int tables;
2887 int frames;
2888 int break_long_lines;
2889 int images;
2890 int image_names;
2891 int margin;
2892 int num_links;
2893 int table_order;
2894 int auto_refresh;
2895 int font_size;
2896 int display_images;
2897 int image_scale;
2898 int porn_enable;
2899 int target_in_new_window;
2900 int t_text_color;
2901 int t_link_color;
2902 int t_background_color;
2903 int t_ignore_document_color;
2904 int g_text_color;
2905 int g_link_color;
2906 int g_background_color;
2907 int g_ignore_document_color;
2908 };
2909
2910
2911 /* IMPORTANT!!!!!
2912 * if you add anything, fix it in compare_opt and if you add it into
2913 * document_setup, fix it in ds2do too
2914 */
2915
2916 struct document_options {
2917 int xw, yw; /* size of window */
2918 int xp, yp; /* pos of window */
2919 int scrolling;
2920 int col, cp, assume_cp, hard_assume;
2921 int braille;
2922 int tables, frames, break_long_lines, images, image_names, margin;
2923 int js_enable;
2924 int plain;
2925 int num_links, table_order;
2926 int auto_refresh;
2927 struct rgb default_fg;
2928 struct rgb default_bg;
2929 struct rgb default_link;
2930 unsigned char *framename;
2931 int font_size;
2932 int display_images;
2933 int image_scale;
2934 int porn_enable;
2935 tcount gamma_stamp;
2936 int real_cp; /* codepage of document. Does not really belong here. Must not be compared. Used only in get_attr_val */
2937 };
2938
color2rgb(struct rgb * rgb,int color)2939 static inline void color2rgb(struct rgb *rgb, int color)
2940 {
2941 memset(rgb, 0, sizeof(struct rgb));
2942 rgb->r = (color >> 16) & 0xff;
2943 rgb->g = (color >> 8) & 0xff;
2944 rgb->b = color & 0xff;
2945 }
2946
ds2do(struct document_setup * ds,struct document_options * doo,int col)2947 static inline void ds2do(struct document_setup *ds, struct document_options *doo, int col)
2948 {
2949 doo->assume_cp = ds->assume_cp;
2950 doo->hard_assume = ds->hard_assume;
2951 doo->tables = ds->tables;
2952 doo->frames = ds->frames;
2953 doo->break_long_lines = ds->break_long_lines;
2954 doo->images = ds->images;
2955 doo->image_names = ds->image_names;
2956 doo->margin = ds->margin;
2957 doo->num_links = ds->num_links;
2958 doo->table_order = ds->table_order;
2959 doo->auto_refresh = ds->auto_refresh;
2960 doo->font_size = ds->font_size;
2961 doo->display_images = ds->display_images;
2962 doo->image_scale = ds->image_scale;
2963 doo->porn_enable = ds->porn_enable;
2964 if (!F) {
2965 if (!col) {
2966 doo->default_fg = palette_16_colors[7];
2967 doo->default_bg = palette_16_colors[0];
2968 doo->default_link = palette_16_colors[15];
2969 } else {
2970 doo->default_fg = palette_16_colors[ds->t_text_color];
2971 doo->default_bg = palette_16_colors[ds->t_background_color];
2972 doo->default_link = palette_16_colors[ds->t_link_color];
2973 }
2974 }
2975 #ifdef G
2976 else {
2977 color2rgb(&doo->default_fg, ds->g_text_color);
2978 color2rgb(&doo->default_bg, ds->g_background_color);
2979 color2rgb(&doo->default_link, ds->g_link_color);
2980 }
2981 #endif
2982 }
2983
2984 struct node {
2985 list_entry_1st
2986 int x, y;
2987 int xw, yw;
2988 list_entry_last
2989 };
2990
2991 struct search {
2992 int idx;
2993 int x, y;
2994 unsigned short n;
2995 unsigned short co;
2996 };
2997
2998 struct frameset_desc;
2999
3000 struct frame_desc {
3001 struct frameset_desc *subframe;
3002 unsigned char *name;
3003 unsigned char *url;
3004 int marginwidth;
3005 int marginheight;
3006 int line;
3007 int xw, yw;
3008 unsigned char scrolling;
3009 };
3010
3011 struct frameset_desc {
3012 int n; /* = x * y */
3013 int x, y; /* velikost */
3014 int xp, yp; /* pozice pri pridavani */
3015 #ifdef JS
3016 unsigned char *onload_code;
3017 #endif
3018 struct frame_desc f[1];
3019 };
3020
3021 struct f_data;
3022
3023 #ifdef G
3024
3025 #define SHAPE_DEFAULT 0
3026 #define SHAPE_RECT 1
3027 #define SHAPE_CIRCLE 2
3028 #define SHAPE_POLY 3
3029
3030 struct map_area {
3031 int shape;
3032 int *coords;
3033 int ncoords;
3034 int link_num;
3035 };
3036
3037 struct image_map {
3038 int n_areas;
3039 struct map_area area[1];
3040 };
3041
3042 struct background {
3043 int sRGB; /* This is 3*8 bytes with sRGB_gamma (in sRGB space).
3044 This is not rounded. */
3045 long color;
3046 tcount gamma_stamp;
3047 };
3048
3049 struct f_data_c;
3050
3051 #define G_OBJ_ALIGN_SPECIAL (MAXINT - 2)
3052 #define G_OBJ_ALIGN_MIDDLE (MAXINT - 2)
3053 #define G_OBJ_ALIGN_TOP (MAXINT - 1)
3054
3055 struct g_object {
3056 /* public data --- must be same in all g_object* structures */
3057 void (*mouse_event)(struct f_data_c *, struct g_object *, int, int, int);
3058 /* pos is relative to object */
3059 void (*draw)(struct f_data_c *, struct g_object *, int, int);
3060 /* absolute pos on screen */
3061 void (*destruct)(struct g_object *);
3062 void (*get_list)(struct g_object *, void (*)(struct g_object *parent, struct g_object *child));
3063 int x, y, xw, yw;
3064 struct g_object *parent;
3065 };
3066
3067 #ifndef REORDER_LIST_ENTRIES
3068 #define go_go_head_1st struct g_object go;
3069 #define go_head_last
3070 #else
3071 #define go_go_head_1st
3072 #define go_head_last struct g_object go;
3073 #endif
3074
3075 struct g_object_text_image {
3076 go_go_head_1st
3077 int link_num;
3078 int link_order;
3079 struct image_map *map;
3080 int ismap;
3081 go_head_last
3082 };
3083
3084 struct g_object_text {
3085 #ifndef REORDER_LIST_ENTRIES
3086 struct g_object_text_image goti;
3087 #endif
3088 struct style *style;
3089 int srch_pos;
3090 #ifdef REORDER_LIST_ENTRIES
3091 struct g_object_text_image goti;
3092 #endif
3093 unsigned char text[1];
3094 };
3095
3096 struct g_object_line {
3097 go_go_head_1st
3098 struct background *bg;
3099 int n_entries;
3100 go_head_last
3101 struct g_object *entries[1];
3102 };
3103
3104 struct g_object_area {
3105 go_go_head_1st
3106 struct background *bg;
3107 int n_lines;
3108 go_head_last
3109 struct g_object_line *lines[1];
3110 };
3111
3112 struct table;
3113
3114 struct g_object_table {
3115 go_go_head_1st
3116 struct table *t;
3117 go_head_last
3118 };
3119
3120 struct g_object_tag {
3121 go_go_head_1st
3122 #ifdef REORDER_LIST_ENTRIES
3123 unsigned char pad;
3124 #endif
3125 go_head_last
3126 /* private data... */
3127 unsigned char name[1];
3128 };
3129
3130 #define IM_PNG 0
3131 #define IM_GIF 1
3132 #define IM_XBM 2
3133
3134 #ifdef HAVE_JPEG
3135 #define IM_JPG 3
3136 #endif /* #ifdef HAVE_JPEG */
3137
3138 #ifdef HAVE_TIFF
3139 #define IM_TIFF 4
3140 #endif /* #ifdef HAVE_TIFF */
3141
3142 #ifdef HAVE_SVG
3143 #define IM_SVG 5
3144 #endif /* #ifdef HAVE_SVG */
3145
3146 #define MEANING_DIMS 0
3147 #define MEANING_AUTOSCALE 1
3148 struct cached_image {
3149 list_entry_1st
3150 int cimg_refcount;
3151
3152 struct cached_image **hash_backlink;
3153 struct cached_image *hash_fwdlink;
3154
3155 int background_color; /* nezaokrouhlene pozadi:
3156 * sRGB, (r<<16)+(g<<8)+b */
3157 unsigned char *url;
3158 ssize_t wanted_xw, wanted_yw; /* This is what is written in the alt.
3159 If some dimension is omitted, then
3160 it's <0. This is what was requested
3161 when the image was created. */
3162 int wanted_xyw_meaning; /* MEANING_DIMS or MEANING_AUTOSCALE.
3163 The meaning of wanted_xw and wanted_yw. */
3164 int scale; /* How is the image scaled */
3165 unsigned aspect; /* What aspect ratio the image is for. But the
3166 PNG aspect is ignored :( */
3167
3168 ssize_t xww, yww; /* This is the resulting dimensions on the screen
3169 measured in screen pixels. */
3170
3171 ssize_t width, height; /* From image header.
3172 * If the buffer is allocated,
3173 * it is always allocated to width*height.
3174 * If the buffer is NULL then width and height
3175 * are garbage. We assume these dimensions
3176 * are given in the meter space (not pixel space).
3177 * Which is true for all images except aspect
3178 * PNG, but we don't support aspect PNG yet.
3179 */
3180 unsigned char image_type; /* IM_??? constant */
3181 unsigned char *buffer; /* Buffer with image data */
3182 unsigned char buffer_bytes_per_pixel; /* 3 or 4 or 6 or 8
3183 * 3: RGB
3184 * 4: RGBA
3185 * 6: RRGGBB
3186 * 8: RRGGBBAA
3187 */
3188 float red_gamma, green_gamma, blue_gamma;
3189 /* data=light_from_monitor^[red|green|blue]_gamma.
3190 * i. e. 0.45455 is here if the image is in sRGB
3191 * makes sense only if buffer is !=NULL
3192 */
3193 tcount gamma_stamp; /* Number that is increased every gamma change */
3194 struct bitmap bmp; /* Registered bitmap. bmp.x=-1 and bmp.y=-1
3195 * if the bmp is not registered.
3196 */
3197 unsigned char bmp_used;
3198 int last_length; /* length of cache entry at which last decoding was
3199 * done. Makes sense only if reparse==0
3200 */
3201 tcount last_count; /* Always valid. */
3202 tcount last_count2; /* Always valid. */
3203 void *decoder; /* Decoder unfinished work. If NULL, decoder
3204 * has finished or has not yet started.
3205 */
3206 int rows_added; /* 1 if some rows were added inside the decoder */
3207 unsigned char state; /* 0...3 or 8...15 */
3208 unsigned char strip_optimized; /* 0 no strip optimization
3209 1 strip-optimized (no buffer allocated permanently
3210 and bitmap is always allocated)
3211 */
3212 unsigned char eof_hit;
3213 int *dregs; /* Only for stip-optimized cached images */
3214 unsigned short *gamma_table; /* When suitable and source is 8 bits per pixel,
3215 * this is allocated to 256*3*sizeof(*gamma_table)
3216 * = 1536 bytes and speeds up the gamma calculations
3217 * tremendously */
3218 list_entry_last
3219 };
3220
3221 struct additional_file;
3222
3223 struct g_object_image {
3224 #ifndef REORDER_LIST_ENTRIES
3225 struct g_object_text_image goti;
3226 #endif
3227 /* x,y: coordinates
3228 xw, yw: width on the screen, or <0 if
3229 not yet known. Already scaled. */
3230 /* For html parser. If xw or yw are zero, then entries
3231 background_color
3232 af
3233 width
3234 height
3235 image_type
3236 buffer
3237 buffer_bytes_per_pixel
3238 *_gamma
3239 gamma_stamp
3240 bmp
3241 last_length
3242 last_count2
3243 decoder
3244 rows_added
3245 reparse
3246 are uninitialized and thus garbage
3247 */
3248
3249 /* End of compatibility with g_object_text */
3250
3251 list_entry_1st
3252
3253 struct cached_image *cimg;
3254 struct additional_file *af;
3255
3256 long id;
3257 unsigned char *name;
3258 unsigned char *alt;
3259 int vspace, hspace, border;
3260 unsigned char *orig_src;
3261 unsigned char *src;
3262 int background; /* Remembered background from insert_image
3263 * (g_part->root->bg->sRGB)
3264 */
3265 int xyw_meaning;
3266
3267 list_entry_last
3268 #ifdef REORDER_LIST_ENTRIES
3269 struct g_object_text_image goti;
3270 #endif
3271 };
3272
3273 void refresh_image(struct f_data_c *fd, struct g_object *img, uttime tm);
3274
3275 #endif
3276
3277 struct additional_file *request_additional_file(struct f_data *f, unsigned char *url);
3278
3279 struct js_event_spec {
3280 #ifdef JS
3281 unsigned char *move_code;
3282 unsigned char *over_code;
3283 unsigned char *out_code;
3284 unsigned char *down_code;
3285 unsigned char *up_code;
3286 unsigned char *click_code;
3287 unsigned char *dbl_code;
3288 unsigned char *blur_code;
3289 unsigned char *focus_code;
3290 unsigned char *change_code;
3291 unsigned char *keypress_code;
3292 unsigned char *keyup_code;
3293 unsigned char *keydown_code;
3294 #else
3295 char dummy;
3296 #endif
3297 };
3298
3299 /*
3300 * warning: if you add more additional file stuctures, you must
3301 * set RQ upcalls correctly
3302 */
3303
3304 #define AF_HASH_SIZE 1024
3305
3306 struct additional_files {
3307 int refcount;
3308 struct list_head af; /* struct additional_file */
3309 struct additional_file *hash[AF_HASH_SIZE];
3310 };
3311
3312 struct additional_file {
3313 list_entry_1st
3314 struct additional_file *hash_fwdlink;
3315 struct object_request *rq;
3316 tcount use_tag;
3317 tcount use_tag2;
3318 int need_reparse;
3319 int unknown_image_size;
3320 list_entry_last
3321 unsigned char url[1];
3322 };
3323
3324 #ifdef G
3325 struct image_refresh {
3326 list_entry_1st
3327 struct g_object *img;
3328 uttime tim;
3329 uttime start;
3330 list_entry_last
3331 };
3332 #endif
3333
3334 struct f_data {
3335 list_entry_1st
3336 struct session *ses;
3337 struct f_data_c *fd;
3338 struct object_request *rq;
3339 tcount use_tag;
3340 struct additional_files *af;
3341 struct document_options opt;
3342 unsigned char *title;
3343 int cp, ass;
3344 int x, y; /* size of document */
3345 uttime time_to_get;
3346 uttime time_to_draw;
3347 struct frameset_desc *frame_desc;
3348 int frame_desc_link; /* if != 0, do not free frame_desc because it is link */
3349
3350 /* text only */
3351 int bg;
3352 struct line *data;
3353 struct link *links;
3354 int nlinks;
3355 struct list_head compressed_chars;
3356 #ifdef JS
3357 struct js_event_spec **link_events;
3358 int nlink_events;
3359 #endif
3360 struct link **lines1;
3361 struct link **lines2;
3362 struct list_head nodes; /* struct node */
3363 struct search *search_pos;
3364 char_t *search_chr;
3365 int nsearch_chr;
3366 int nsearch_pos;
3367 int *slines1;
3368 int *slines2;
3369
3370 struct list_head forms; /* struct form_control */
3371 struct list_head tags; /* struct tag */
3372
3373 #ifdef JS
3374 int are_there_scripts;
3375 unsigned char *script_href_base;
3376 #endif
3377
3378 unsigned char *refresh;
3379 int refresh_seconds;
3380
3381 int uncacheable; /* cannot be cached - either created from source modified by document.write or modified by javascript */
3382
3383 #ifdef JS
3384 struct js_event_spec *js_event;
3385 #endif
3386
3387 /* graphics only */
3388 #ifdef G
3389 struct g_object *root;
3390 struct g_object *locked_on;
3391
3392 unsigned char *srch_string;
3393 int srch_string_size;
3394
3395 unsigned char *last_search;
3396 int *search_positions;
3397 int *search_lengths;
3398 int n_search_positions;
3399 int hlt_pos; /* index of first highlighted byte */
3400 int hlt_len; /* length of highlighted bytes; (hlt_pos+hlt_len) is index of last highlighted character */
3401 int start_highlight_x;
3402 int start_highlight_y;
3403 struct list_head images; /* list of all images in this f_data */
3404 int n_images; /* pocet obrazku (tim se obrazky taky identifikujou), po kazdem pridani obrazku se zvedne o 1 */
3405
3406 struct list_head image_refresh;
3407 #endif
3408 list_entry_last
3409 };
3410
get_char_attr(struct f_data * f,int x,int y,unsigned * ch,unsigned char * at)3411 static inline void get_char_attr(struct f_data *f, int x, int y, unsigned *ch, unsigned char *at)
3412 {
3413 struct line *ln = &f->data[y];
3414 if (ln->allocated >= 0) {
3415 *ch = ln->u.du[x].ch;
3416 *at = ln->u.du[x].at;
3417 } else {
3418 *ch = ln->u.dc[x];
3419 *at = ln->allocated & 0xff;
3420 }
3421 }
3422
3423 struct view_state {
3424 int refcount;
3425
3426 int view_pos;
3427 int view_posx;
3428 int orig_view_pos;
3429 int orig_view_posx;
3430 int current_link; /* platny jen kdyz je <f_data->n_links */
3431 int orig_link;
3432 int frame_pos;
3433 int plain;
3434 struct form_state *form_info;
3435 int form_info_len;
3436 int brl_x;
3437 int brl_y;
3438 int orig_brl_x;
3439 int orig_brl_y;
3440 int brl_in_field;
3441 #ifdef G
3442 int g_display_link;
3443 #endif
3444 };
3445
3446 struct location;
3447
3448 struct f_data_c {
3449 list_entry_1st
3450 struct f_data_c *parent;
3451 struct session *ses;
3452 struct location *loc;
3453 struct view_state *vs;
3454 struct f_data *f_data;
3455 int xw, yw; /* size of window */
3456 int xp, yp; /* pos of window on screen */
3457 int xl, yl; /* last pos of view in window */
3458
3459 int hsb, vsb;
3460 int hsbsize, vsbsize;
3461
3462 struct link_bg *link_bg;
3463 int link_bg_n;
3464 int depth;
3465
3466 struct object_request *rq;
3467 unsigned char *goto_position;
3468 unsigned char *went_to_position;
3469 struct additional_files *af;
3470
3471 struct list_head subframes; /* struct f_data_c */
3472
3473 uttime last_update;
3474 uttime next_update_interval;
3475 int done;
3476 int parsed_done;
3477 int script_t; /* offset of next script to execute */
3478
3479 int active; /* temporary, for draw_doc */
3480
3481 long id; /* unique document identification for javascript */
3482
3483 int marginwidth, marginheight;
3484
3485 #ifdef JS
3486 struct js_state *js;
3487 #endif
3488
3489 struct timer *image_timer;
3490
3491 struct timer *refresh_timer;
3492
3493 #ifdef JS
3494 unsigned char *onload_frameset_code;
3495 #endif
3496 unsigned char scrolling;
3497 unsigned char last_captured;
3498
3499 list_entry_last
3500 };
3501
3502 struct location {
3503 list_entry_1st
3504 struct location *parent;
3505 unsigned char *name; /* frame name */
3506 unsigned char *url;
3507 unsigned char *prev_url; /* allocated string with referrer */
3508 struct list_head subframes; /* struct location */
3509 struct view_state *vs;
3510 unsigned location_id;
3511 list_entry_last
3512 };
3513
3514 #define WTD_NO 0
3515 #define WTD_FORWARD 1
3516 #define WTD_IMGMAP 2
3517 #define WTD_RELOAD 3
3518 #define WTD_BACK 4
3519
3520 #define cur_loc(x) list_struct((x)->history.next, struct location)
3521
3522 struct kbdprefix {
3523 int rep;
3524 int rep_num;
3525 int prefix;
3526 };
3527
3528 struct download {
3529 list_entry_1st
3530 unsigned char *url;
3531 struct status stat;
3532 unsigned char decompress;
3533 unsigned char *cwd;
3534 unsigned char *orig_file;
3535 unsigned char *file;
3536 off_t last_pos;
3537 off_t file_shift;
3538 int handle;
3539 int redirect_cnt;
3540 int downloaded_something;
3541 unsigned char *prog;
3542 int prog_flag_block;
3543 time_t remotetime;
3544 struct session *ses;
3545 struct window *win;
3546 struct window *ask;
3547 list_entry_last
3548 };
3549
3550 extern struct list_head downloads;
3551
3552 struct session {
3553 list_entry_1st
3554 struct list_head history; /* struct location */
3555 struct list_head forward_history;
3556 struct terminal *term;
3557 struct window *win;
3558 int id;
3559 unsigned char *st; /* status line string */
3560 unsigned char *st_old; /* old status line --- compared with st to prevent cursor flicker */
3561 unsigned char *default_status; /* default value of the status line */
3562 struct f_data_c *screen;
3563 struct object_request *rq;
3564 void (*wtd)(struct session *);
3565 unsigned char *wtd_target;
3566 struct f_data_c *wtd_target_base;
3567 unsigned char *wanted_framename;
3568 int wtd_refresh;
3569 int wtd_num_steps;
3570 unsigned char *goto_position;
3571 struct document_setup ds;
3572 struct kbdprefix kbdprefix;
3573 int reloadlevel;
3574 struct object_request *tq;
3575 unsigned char *tq_prog;
3576 int tq_prog_flag_block;
3577 int tq_prog_flag_direct;
3578 unsigned char *dn_url;
3579 int dn_allow_flags;
3580 unsigned char *search_word;
3581 unsigned char *last_search_word;
3582 int search_direction;
3583 int exit_query;
3584 struct list_head format_cache; /* struct f_data */
3585
3586 unsigned char *imgmap_href_base;
3587 unsigned char *imgmap_target_base;
3588
3589 #ifdef JS
3590 unsigned char *defered_url;
3591 unsigned char *defered_target;
3592 struct f_data_c *defered_target_base;
3593 int defered_data; /* for submit: form number, jinak -1 */
3594 tcount defered_seq;
3595 #endif
3596
3597 int brl_cursor_mode;
3598
3599 #ifdef G
3600 int locked_link; /* for graphics - when link is locked on FIELD/AREA */
3601 int scrolling;
3602 int scrolltype;
3603 int scrolloff;
3604
3605 int back_size;
3606 #endif
3607 list_entry_last
3608 };
3609
3610 struct dialog_data;
3611
3612 int f_is_finished(struct f_data *f);
3613 unsigned long formatted_info(int);
3614 int shrink_format_cache(int u);
3615 void init_fcache(void);
3616 void html_interpret_recursive(struct f_data_c *);
3617 void fd_loaded(struct object_request *, void *);
3618
3619 extern struct list_head sessions;
3620
3621 unsigned char *encode_url(unsigned char *);
3622 unsigned char *decode_url(unsigned char *);
3623 struct session *get_download_ses(struct download *);
3624 unsigned char *subst_file(unsigned char *, unsigned char *, int);
3625 int are_there_downloads(void);
3626 unsigned char get_session_attribute(struct session *, int);
3627 unsigned char *translate_download_file(unsigned char *);
3628 void free_strerror_buf(void);
3629 int get_error_from_errno(int errn);
3630 unsigned char *get_err_msg(int, struct terminal *);
3631 void change_screen_status(struct session *);
3632 void print_screen_status(struct session *);
3633 void print_progress(struct session *, unsigned char *);
3634 void print_error_dialog(struct session *, struct status *, unsigned char *);
3635 void start_download(struct session *, unsigned char *, int);
3636 int test_abort_downloads_to_file(unsigned char *, unsigned char *, int);
3637 void abort_all_downloads(void);
3638 unsigned char *download_percentage(struct download *down, int pad);
3639 void download_window_function(struct dialog_data *dlg);
3640 void display_download(struct terminal *, void *, void *);
3641 struct f_data *cached_format_html(struct f_data_c *fd, struct object_request *rq, unsigned char *url, struct document_options *opt, int *cch, int report_status);
3642 struct f_data_c *create_f_data_c(struct session *, struct f_data_c *);
3643 void reinit_f_data_c(struct f_data_c *);
3644 int f_data_c_allow_flags(struct f_data_c *fd);
3645 #define CDF_RESTRICT_PERMISSION 1
3646 #define CDF_EXCL 2
3647 #define CDF_NOTRUNC 4
3648 #define CDF_NO_POPUP_ON_EEXIST 8
3649 int create_download_file(struct session *, unsigned char *, unsigned char *, int, off_t);
3650 void *create_session_info(int, unsigned char *, unsigned char *, int *);
3651 void win_func(struct window *, struct links_event *, int);
3652 void goto_url_f(struct session *, void (*)(struct session *), unsigned char *, unsigned char *, struct f_data_c *, int, int, int, int);
3653 void goto_url(void *, unsigned char *);
3654 void goto_url_utf8(struct session *, unsigned char *);
3655 void goto_url_not_from_dialog(struct session *, unsigned char *, struct f_data_c *);
3656 void goto_imgmap(struct session *ses, struct f_data_c *fd, unsigned char *url, unsigned char *href, unsigned char *target);
3657 void map_selected(struct terminal *term, void *ld, void *ses_);
3658 void go_back(struct session *, int);
3659 void go_backwards(struct terminal *term, void *psteps, void *ses_);
3660 void reload(struct session *, int);
3661 void cleanup_session(struct session *);
3662 void destroy_session(struct session *);
3663 void ses_destroy_defered_jump(struct session *ses);
3664 struct f_data_c *find_frame(struct session *ses, unsigned char *target, struct f_data_c *base);
3665
3666
3667 /* Information about the current document */
3668 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
3669 unsigned char *get_current_title(struct f_data_c *, unsigned char *, size_t);
3670
3671 /*unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);*/
3672 unsigned char *get_form_url(struct session *ses, struct f_data_c *f, struct form_control *form, int *onsubmit);
3673
3674 /* js.c */
3675
3676 #ifdef JS
3677 struct javascript_context *js_create_context(void *, long);
3678 void js_destroy_context(struct javascript_context *);
3679 void js_execute_code(struct javascript_context *, unsigned char *, int, void (*)(void *));
3680 #endif
3681
3682 /* jsint.c */
3683
3684 #ifdef JS
3685
3686 #define JS_OBJ_MASK 255
3687 #define JS_OBJ_MASK_SIZE 8
3688
3689 #define JS_OBJ_T_UNKNOWN 0
3690 #define JS_OBJ_T_DOCUMENT 1
3691 #define JS_OBJ_T_FRAME 2 /* document a frame se tvari pro mne stejne --Brain */
3692 #define JS_OBJ_T_LINK 3
3693 #define JS_OBJ_T_FORM 4
3694 #define JS_OBJ_T_ANCHOR 5
3695 #define JS_OBJ_T_IMAGE 6
3696 /* form elements */
3697 #define JS_OBJ_T_TEXT 7
3698 #define JS_OBJ_T_PASSWORD 8
3699 #define JS_OBJ_T_TEXTAREA 9
3700 #define JS_OBJ_T_CHECKBOX 10
3701 #define JS_OBJ_T_RADIO 11
3702 #define JS_OBJ_T_SELECT 12
3703 #define JS_OBJ_T_SUBMIT 13
3704 #define JS_OBJ_T_RESET 14
3705 #define JS_OBJ_T_HIDDEN 15
3706 #define JS_OBJ_T_BUTTON 16
3707
3708 extern long js_zaflaknuto_pameti;
3709
3710 extern struct history js_get_string_history;
3711 extern int js_manual_confirmation;
3712
3713 struct js_state {
3714 struct javascript_context *ctx; /* kontext beziciho javascriptu??? */
3715 struct list_head queue; /* struct js_request - list of javascripts to run */
3716 struct js_request *active; /* request is running */
3717 unsigned char *src; /* zdrojak beziciho javascriptu??? */ /* mikulas: ne. to je zdrojak stranky */
3718 int srclen;
3719 int wrote;
3720 int newdata;
3721 };
3722
3723
3724 /* funkce js_get_select_options vraci pole s temito polozkami */
3725 struct js_select_item{
3726 /* index je poradi v poli, ktere vratim, takze se tu nemusi skladovat */
3727 int default_selected;
3728 int selected;
3729 unsigned char *text; /* text, ktery se zobrazuje */
3730 unsigned char *value; /* value, ktera se posila */
3731 };
3732
3733 struct fax_me_tender_string{
3734 void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
3735 unsigned char *string;
3736 };
3737
3738 struct fax_me_tender_int_string{
3739 void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
3740 int num;
3741 unsigned char *string;
3742 };
3743
3744 struct fax_me_tender_string_2_longy{
3745 void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
3746 unsigned char *string;
3747 long doc_id,obj_id;
3748 };
3749
3750 struct fax_me_tender_2_stringy{
3751 void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
3752 unsigned char *string1;
3753 unsigned char *string2;
3754 };
3755
3756 struct fax_me_tender_nothing{
3757 void *ident; /* struct f_data_c*, but JS doesn't know it ;-) */
3758 };
3759
3760 extern tcount jsint_execute_seq;
3761
3762 void javascript_func(struct session *ses, unsigned char *code);
3763 void jsint_run_queue(struct f_data_c *);
3764 long *jsint_resolve(void *context, long obj_id, char *takhle_tomu_u_nas_nadavame,int *n_items);
3765 int jsint_object_type(long);
3766 void jsint_set_cookies(struct f_data_c *fd, int final_flush);
3767 struct f_data_c *jsint_find_document(long doc_id);
3768
3769 void js_upcall_document_write(void *p, unsigned char *str, int len);
3770 void js_upcall_alert(void *struct_fax_me_tender_string);
3771 unsigned char *js_upcall_get_title(void *data);
3772 void js_upcall_set_title(void *data, unsigned char *title);
3773 unsigned char *js_upcall_get_location(void *data);
3774 unsigned char *js_upcall_get_useragent(void *data);
3775 void js_upcall_confirm(void *struct_fax_me_tender_string);
3776 void js_upcall_get_string(void *data);
3777 unsigned char *js_upcall_get_referrer(void *data);
3778 unsigned char *js_upcall_get_appname(void);
3779 unsigned char *js_upcall_get_appcodename(void);
3780 unsigned char *js_upcall_get_appversion(void);
3781 long js_upcall_get_document_id(void *data);
3782 long js_upcall_get_window_id(void *data);
3783 void js_upcall_close_window(void *struct_fax_me_tender_nothing);
3784 unsigned char *js_upcall_document_last_modified(void *data, long document_id);
3785 unsigned char *js_upcall_get_window_name(void *data);
3786 void js_upcall_clear_window(void *);
3787 long *js_upcall_get_links(void *data, long document_id, int *len);
3788 unsigned char *js_upcall_get_link_target(void *data, long document_id, long link_id);
3789 long *js_upcall_get_forms(void *data, long document_id, int *len);
3790 unsigned char *js_upcall_get_form_action(void *data, long document_id, long form_id);
3791 unsigned char *js_upcall_get_form_target(void *data, long document_id, long form_id);
3792 unsigned char *js_upcall_get_form_method(void *data, long document_id, long form_id);
3793 unsigned char *js_upcall_get_form_encoding(void *data, long document_id, long form_id);
3794 unsigned char *js_upcall_get_location_protocol(void *data);
3795 unsigned char *js_upcall_get_location_port(void *data);
3796 unsigned char *js_upcall_get_location_hostname(void *data);
3797 unsigned char *js_upcall_get_location_host(void *data);
3798 unsigned char *js_upcall_get_location_pathname(void *data);
3799 unsigned char *js_upcall_get_location_search(void *data);
3800 unsigned char *js_upcall_get_location_hash(void *data);
3801 long *js_upcall_get_form_elements(void *data, long document_id, long form_id, int *len);
3802 long *js_upcall_get_anchors(void *hej_Hombre, long document_id, int *len);
3803 int js_upcall_get_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id);
3804 void js_upcall_set_checkbox_radio_checked(void *smirak, long document_id, long radio_tv_id, int value);
3805 int js_upcall_get_checkbox_radio_default_checked(void *smirak, long document_id, long radio_tv_id);
3806 void js_upcall_set_checkbox_radio_default_checked(void *smirak, long document_id, long radio_tv_id, int value);
3807 unsigned char *js_upcall_get_form_element_name(void *smirak, long document_id, long ksunt_id);
3808 void js_upcall_set_form_element_name(void *smirak, long document_id, long ksunt_id, unsigned char *name);
3809 unsigned char *js_upcall_get_form_element_default_value(void *smirak, long document_id, long ksunt_id);
3810 void js_upcall_set_form_element_default_value(void *smirak, long document_id, long ksunt_id, unsigned char *name);
3811 void js_upcall_set_form_element_event_handler(void *bidak, long document_id, long ksunt_id, long typ, unsigned char *name);
3812 unsigned char *js_upcall_get_form_element_value(void *smirak, long document_id, long ksunt_id);
3813 void js_upcall_set_form_element_value(void *smirak, long document_id, long ksunt_id, unsigned char *name);
3814 void js_upcall_click(void *smirak, long document_id, long elem_id);
3815 void js_upcall_focus(void *smirak, long document_id, long elem_id);
3816 void js_upcall_blur(void *smirak, long document_id, long elem_id);
3817 void js_upcall_submit(void *bidak, long document_id, long form_id);
3818 void js_upcall_reset(void *bidak, long document_id, long form_id);
3819 int js_upcall_get_radio_length(void *smirak, long document_id, long radio_id); /* radio.length */
3820 int js_upcall_get_select_length(void *smirak, long document_id, long select_id); /* select.length */
3821 int js_upcall_get_select_index(void *smirak, long document_id, long select_id); /* select.selectedIndex */
3822 struct js_select_item* js_upcall_get_select_options(void *smirak, long document_id, long select_id, int *n);
3823 void js_upcall_goto_url(void* struct_fax_me_tender_string);
3824 int js_upcall_get_history_length(void *context);
3825 void js_upcall_goto_history(void* data);
3826 void js_upcall_set_default_status(void *context, unsigned char *tak_se_ukaz_Kolbene);
3827 unsigned char *js_upcall_get_default_status(void *context);
3828 void js_upcall_set_status(void *context, unsigned char *tak_se_ukaz_Kolbene);
3829 unsigned char *js_upcall_get_status(void *context);
3830 unsigned char *js_upcall_get_cookies(void *context);
3831 long *js_upcall_get_images(void *smirak, long document_id, int *len);
3832 long * js_upcall_get_all(void *context, long document_id, int *len);
3833 int js_upcall_get_image_width(void *smirak, long document_id, long image_id);
3834 int js_upcall_get_image_height(void *smirak, long document_id, long image_id);
3835 int js_upcall_get_image_border(void *smirak, long document_id, long image_id);
3836 int js_upcall_get_image_vspace(void *smirak, long document_id, long image_id);
3837 int js_upcall_get_image_hspace(void *smirak, long document_id, long image_id);
3838 unsigned char *js_upcall_get_image_name(void *smirak, long document_id, long image_id);
3839 unsigned char *js_upcall_get_image_alt(void *smirak, long document_id, long image_id);
3840 void js_upcall_set_image_name(void *smirak, long document_id, long image_id, unsigned char *name);
3841 void js_upcall_set_image_alt(void *smirak, long document_id, long image_id, unsigned char *alt);
3842 unsigned char *js_upcall_get_image_src(void *smirak, long document_id, long image_id);
3843 void js_upcall_set_image_src(void *chuligane);
3844 int js_upcall_image_complete(void *smirak, long document_id, long image_id);
3845 long js_upcall_get_parent(void *smirak, long frame_id);
3846 long js_upcall_get_frame_top(void *smirak, long frame_id);
3847 long * js_upcall_get_subframes(void *smirak, long frame_id, int *count);
3848 void js_upcall_set_form_action(void *context, long document_id, long form_id, unsigned char *action);
3849
3850
3851 void js_downcall_vezmi_true(void *context);
3852 void js_downcall_vezmi_false(void *context);
3853 void js_downcall_vezmi_null(void *context);
3854 void js_downcall_game_over(void *context);
3855 void js_downcall_quiet_game_over(void *context);
3856 void js_downcall_vezmi_int(void *context, int i);
3857 void js_downcall_vezmi_float(void*context,double f);
3858 /*void js_downcall_vezmi_float(void *context, float f);*/
3859 void js_downcall_vezmi_string(void *context, unsigned char *string);
3860
3861 #endif
3862
3863 void jsint_execute_code(struct f_data_c *, unsigned char *, int, int, int, int, struct links_event *);
3864 void jsint_destroy(struct f_data_c *);
3865 void jsint_scan_script_tags(struct f_data_c *);
3866 int jsint_get_source(struct f_data_c *, unsigned char **, size_t *);
3867
3868 /* bfu.c */
3869
3870 extern struct style *bfu_style_wb, *bfu_style_bw, *bfu_style_wb_b, *bfu_style_bw_u, *bfu_style_bw_mono, *bfu_style_wb_mono, *bfu_style_wb_mono_u;
3871 extern long bfu_bg_color, bfu_fg_color;
3872
3873 struct memory_list {
3874 int n;
3875 void *p[1];
3876 };
3877
3878 struct memory_list *getml(void *, ...);
3879 void add_to_ml(struct memory_list **, ...);
3880 void freeml(struct memory_list *);
3881
3882 void init_bfu(void);
3883 void shutdown_bfu(void);
3884
3885 #define DIALOG_LB gf_val(DIALOG_LEFT_BORDER + DIALOG_LEFT_INNER_BORDER + 1, G_DIALOG_LEFT_BORDER + G_DIALOG_VLINE_SPACE + 1 + G_DIALOG_LEFT_INNER_BORDER)
3886 #define DIALOG_TB gf_val(DIALOG_TOP_BORDER + DIALOG_TOP_INNER_BORDER + 1, G_DIALOG_TOP_BORDER + G_DIALOG_HLINE_SPACE + 1 + G_DIALOG_TOP_INNER_BORDER)
3887
3888 #define LL gf_val(1, G_BFU_FONT_SIZE)
3889
3890 extern unsigned char m_bar;
3891
3892 #define M_BAR (&m_bar)
3893
3894 struct menu_item {
3895 unsigned char *text;
3896 unsigned char *rtext;
3897 unsigned char *hotkey;
3898 void (*func)(struct terminal *, void *, void *);
3899 void *data;
3900 int in_m;
3901 int free_i;
3902 };
3903
3904 #define MENU_FREE_ITEMS 1
3905 #define MENU_FREE_TEXT 2
3906 #define MENU_FREE_RTEXT 4
3907 #define MENU_FREE_HOTKEY 8
3908 #define MENU_FONT_LIST 32
3909 #define MENU_FONT_LIST_BOLD 64
3910 #define MENU_FONT_LIST_MONO 128
3911
3912 struct menu {
3913 int selected;
3914 int view;
3915 int nview;
3916 int xp, yp;
3917 int x, y, xw, yw;
3918 int ni;
3919 void *data;
3920 struct window *win;
3921 struct menu_item *items;
3922 #ifdef G
3923 unsigned char **hktxt1;
3924 unsigned char **hktxt2;
3925 unsigned char **hktxt3;
3926 int xl1, yl1, xl2, yl2;
3927 #endif
3928 void (*free_function)(void *);
3929 void *free_data;
3930 unsigned hotkeys[1];
3931 };
3932
3933 struct mainmenu {
3934 int selected;
3935 int sp;
3936 int ni;
3937 void *data;
3938 struct window *win;
3939 struct menu_item *items;
3940 #ifdef G
3941 int xl1, yl1, xl2, yl2;
3942 #endif
3943 unsigned hotkeys[1];
3944 };
3945
3946 struct history_item {
3947 list_entry_1st
3948 list_entry_last
3949 unsigned char str[1];
3950 };
3951
3952 struct history {
3953 int n;
3954 struct list_head items;
3955 };
3956
3957 #define free_history(h) free_list(struct history_item, (h).items)
3958
3959 #define D_END 0
3960 #define D_CHECKBOX 1
3961 #define D_FIELD 2
3962 #define D_FIELD_PASS 3
3963 #define D_BUTTON 4
3964
3965 #define B_ENTER 1
3966 #define B_ESC 2
3967
3968 struct dialog_item_data;
3969
3970 typedef void (*msg_button_fn)(void *);
3971 typedef void (*input_field_button_fn)(void *, unsigned char *);
3972
3973 struct dialog_item {
3974 int type;
3975 int gid, gnum; /* for buttons: gid - flags B_XXX */ /* for fields: min/max */ /* for box: gid is box height */
3976 int (*fn)(struct dialog_data *, struct dialog_item_data *);
3977 struct history *history;
3978 int dlen;
3979 unsigned char *data;
3980 void *udata; /* for box: holds list */
3981 union {
3982 msg_button_fn msg_fn;
3983 input_field_button_fn input_fn;
3984 } u;
3985 unsigned char *text;
3986 };
3987
3988 struct dialog_item_data {
3989 int x, y, l;
3990 int vpos, cpos;
3991 int checked;
3992 struct dialog_item *item;
3993 struct list_head history;
3994 struct list_head *cur_hist;
3995 unsigned char *cdata;
3996 };
3997
3998 #define EVENT_PROCESSED 0
3999 #define EVENT_NOT_PROCESSED 1
4000
4001 struct dialog {
4002 unsigned char *title;
4003 void (*fn)(struct dialog_data *);
4004 int (*handle_event)(struct dialog_data *, struct links_event *);
4005 void (*abort)(struct dialog_data *);
4006 void *udata;
4007 void *udata2;
4008 int align;
4009 void (*refresh)(void *);
4010 void *refresh_data;
4011 struct dialog_item items[1];
4012 };
4013
4014 struct dialog_data {
4015 struct window *win;
4016 struct dialog *dlg;
4017 int x, y, xw, yw;
4018 int n;
4019 int selected;
4020 struct memory_list *ml;
4021 int brl_y;
4022 #ifdef G
4023 struct rect_set *s;
4024 struct rect r;
4025 struct rect rr;
4026 #endif
4027 struct dialog_item_data items[1];
4028 };
4029
4030 struct menu_item *new_menu(int);
4031 void add_to_menu(struct menu_item **, unsigned char *, unsigned char *, unsigned char *, void (*)(struct terminal *, void *, void *), void *, int, int);
4032 void do_menu(struct terminal *, struct menu_item *, void *);
4033 void do_menu_selected(struct terminal *, struct menu_item *, void *, int, void (*)(void *), void *);
4034 void do_mainmenu(struct terminal *, struct menu_item *, void *, int);
4035 void do_dialog(struct terminal *, struct dialog *, struct memory_list *);
4036 void dialog_func(struct window *, struct links_event *, int);
4037 int check_number(struct dialog_data *, struct dialog_item_data *);
4038 int check_hex_number(struct dialog_data *, struct dialog_item_data *);
4039 int check_float(struct dialog_data *, struct dialog_item_data *);
4040 int check_nonempty(struct dialog_data *, struct dialog_item_data *);
4041 int check_local_ip_address(struct dialog_data *, struct dialog_item_data *);
4042 int check_local_ipv6_address(struct dialog_data *, struct dialog_item_data *);
4043 void max_text_width(struct terminal *, unsigned char *, int *, int);
4044 void min_text_width(struct terminal *, unsigned char *, int *, int);
4045 int dlg_format_text(struct dialog_data *, struct terminal *, unsigned char *, int, int *, int, int *, unsigned char, int);
4046 void dlg_format_text_and_field(struct dialog_data *, struct terminal *, unsigned char *, struct dialog_item_data *, int, int *, int, int *, unsigned char, int);
4047 void max_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
4048 void min_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
4049 void dlg_format_buttons(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, int);
4050 void checkboxes_width(struct terminal *, unsigned char * const *, int, int *, void (*)(struct terminal *, unsigned char *, int *, int));
4051 void dlg_format_checkbox(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, unsigned char *);
4052 void dlg_format_checkboxes(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, unsigned char * const *);
4053 void dlg_format_field(struct dialog_data *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
4054 void max_group_width(struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int *);
4055 void min_group_width(struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int *);
4056 void dlg_format_group(struct dialog_data *, struct terminal *, unsigned char * const *, struct dialog_item_data *, int, int, int *, int, int *);
4057 /*void dlg_format_box(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);*/
4058 void checkbox_list_fn(struct dialog_data *);
4059 void group_fn(struct dialog_data *);
4060 void center_dlg(struct dialog_data *);
4061 void draw_dlg(struct dialog_data *);
4062 void display_dlg_item(struct dialog_data *, struct dialog_item_data *, int);
4063 int check_dialog(struct dialog_data *);
4064 void get_dialog_data(struct dialog_data *);
4065 int ok_dialog(struct dialog_data *, struct dialog_item_data *);
4066 int cancel_dialog(struct dialog_data *, struct dialog_item_data *);
4067
4068 void msg_box_fn(struct dialog_data *dlg);
4069 void msg_box_null(void *);
4070 #define MSG_BOX_END ((unsigned char *)NULL)
4071 void msg_box(struct terminal *, struct memory_list *, unsigned char *, int, /*unsigned char *, void *, int,*/ ...);
4072 /* msg_box arguments:
4073 * terminal,
4074 * blocks to free,
4075 * title,
4076 * alignment,
4077 * strings (followed by MSG_BOX_END),
4078 * data for function,
4079 * number of buttons,
4080 * button title, function, hotkey,
4081 * ... other buttons
4082 */
4083
4084 void input_field_null(void *d_, unsigned char *s_);
4085 void input_field(struct terminal *, struct memory_list *, unsigned char *, unsigned char *, void *, struct history *, int, unsigned char *, int, int, int (*)(struct dialog_data *, struct dialog_item_data *), int n, ...);
4086 /* input_field arguments:
4087 * terminal,
4088 * blocks to free,
4089 * title,
4090 * question,
4091 * data for functions,
4092 * history,
4093 * length,
4094 * string to fill the dialog with,
4095 * minimal value,
4096 * maximal value,
4097 * check_function,
4098 * the number of buttons,
4099 * OK button text,
4100 * ok function,
4101 * CANCEL button text,
4102 * cancel function,
4103 *
4104 * field can have multiple buttons and functions, and finally NULL
4105 * (warning: if there's no cancel function, there will be two NULLs in
4106 * a call). Functions have type
4107 * void (*fn)(void *data, unsigned char *text), only the last one has type
4108 * void (*fn)(void *data). Check it carefully because the compiler wont!
4109 */
4110 void add_to_history(struct terminal *, struct history *, unsigned char *);
4111
4112 int find_msg_box(struct terminal *term, unsigned char *title, int (*sel)(void *, void *), void *data);
4113
4114 /* menu.c */
4115
4116 extern struct history goto_url_history;
4117
4118 void activate_keys(struct session *ses);
4119 void reset_settings_for_tor(void);
4120 int save_proxy(int charset, unsigned char *result, unsigned char *proxy);
4121 int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy_list);
4122 void dialog_html_options(struct session *ses);
4123 void activate_bfu_technology(struct session *, int);
4124 void dialog_goto_url(struct session *ses, unsigned char *url);
4125 void dialog_save_url(struct session *ses);
4126 void free_history_lists(void);
4127 void query_file(struct session *, unsigned char *, unsigned char *, void (*)(struct session *, unsigned char *, int), void (*)(void *), int);
4128 #define DOWNLOAD_DEFAULT 0
4129 #define DOWNLOAD_OVERWRITE 1
4130 #define DOWNLOAD_CONTINUE 2
4131 void search_dlg(struct session *, struct f_data_c *, int);
4132 void search_back_dlg(struct session *, struct f_data_c *, int);
4133 void exit_prog(struct terminal *, void *, void *);
4134 void really_exit_prog(void *ses_);
4135 void query_exit(struct session *ses);
4136
4137 /* charsets.c */
4138
4139 #include "codepage.h"
4140
4141 extern int utf8_table;
4142
4143 struct conv_table {
4144 int t;
4145 union {
4146 unsigned char *str;
4147 struct conv_table *tbl;
4148 } u;
4149 };
4150
4151 struct conv_table *get_translation_table(int, int);
is_entity_terminator(unsigned char c)4152 static inline int is_entity_terminator(unsigned char c) { return c <= ' ' || c == ';' || c == '&' || c == '/' || c == '?'; }
4153 int get_entity_number(unsigned char *st, int l);
4154 unsigned char *get_entity_string(unsigned char *, int, int);
4155 unsigned char *convert_string(struct conv_table *, unsigned char *, int, struct document_options *);
4156 unsigned char *convert(int from, int to, unsigned char *c, struct document_options *dopt);
4157 int get_cp_index(unsigned char *);
4158 unsigned char *get_cp_name(int);
4159 unsigned char *get_cp_mime_name(int);
4160 void free_conv_table(void);
4161 unsigned char *encode_utf_8(int);
4162 unsigned char *u2cp(int u, int to, int fallback);
4163 int cp2u(unsigned, int);
4164
4165 unsigned uni_locase(unsigned);
4166 unsigned charset_upcase(unsigned, int);
4167 unsigned uni_upcase(unsigned);
4168 void charset_upcase_string(unsigned char **, int);
4169 unsigned char *unicode_upcase_string(unsigned char *ch);
4170 unsigned char *to_utf8_upcase(unsigned char *str, int cp);
4171 int compare_case_utf8(unsigned char *u1, unsigned char *u2);
4172 int strlen_utf8(unsigned char *s);
4173 unsigned char *cp_strchr(int charset, unsigned char *str, unsigned chr);
4174 void init_charset(void);
4175
4176 unsigned get_utf_8(unsigned char **p);
4177 #define GET_UTF_8(s, c) \
4178 do { \
4179 if ((unsigned char)(s)[0] < 0x80) \
4180 (c) = (s)++[0]; \
4181 else if ((unsigned char)(s)[0] >= 0xc2 && (unsigned char)(s)[0] < 0xe0 &&\
4182 ((unsigned char)(s)[1] & 0xc0) == 0x80) { \
4183 (c) = (unsigned char)(s)[0] * 0x40 + (unsigned char)(s)[1], (c) -= 0x3080, (s) += 2;\
4184 } else \
4185 (c) = get_utf_8(&(s)); \
4186 } while (0)
4187 #define FWD_UTF_8(s) \
4188 do { \
4189 if ((unsigned char)(s)[0] < 0x80) \
4190 (s)++; \
4191 else \
4192 get_utf_8(&(s)); \
4193 } while (0)
4194 #define BACK_UTF_8(p, b) \
4195 do { \
4196 while ((p) > (b)) { \
4197 (p)--; \
4198 if ((*(p) & 0xc0) != 0x80) \
4199 break; \
4200 } \
4201 } while (0)
4202
4203 int cp_len(int cp, unsigned char *s);
4204
4205 extern unsigned char utf_8_1[256];
4206
utf8chrlen(unsigned char c)4207 static inline int utf8chrlen(unsigned char c)
4208 {
4209 unsigned char l = utf_8_1[c];
4210 if (l == 7) return 1;
4211 return 7 - l;
4212 }
4213
GET_TERM_CHAR(struct terminal * term,unsigned char ** str)4214 static inline unsigned GET_TERM_CHAR(struct terminal *term, unsigned char **str)
4215 {
4216 unsigned ch;
4217 #if defined(G) || defined(ENABLE_UTF8)
4218 if (term_charset(term) == utf8_table)
4219 GET_UTF_8(*str, ch);
4220 else
4221 #endif
4222 ch = *(*str)++;
4223 return ch;
4224 }
4225
4226 /* view.c */
4227
4228 unsigned char *textptr_add(unsigned char *t, int i, int cp);
4229 int textptr_diff(unsigned char *t2, unsigned char *t1, int cp);
4230
4231 extern int ismap_link, ismap_x, ismap_y;
4232
4233 void frm_download(struct session *, struct f_data_c *);
4234 void frm_download_image(struct session *, struct f_data_c *);
4235 void frm_view_image(struct session *, struct f_data_c *);
4236 struct format_text_cache_entry *format_text(struct f_data_c *fd, struct form_control *fc, struct form_state *fs);
4237 int area_cursor(struct f_data_c *f, struct form_control *fc, struct form_state *fs);
4238 struct form_state *find_form_state(struct f_data_c *, struct form_control *);
4239 void fixup_select_state(struct form_control *fc, struct form_state *fs);
4240 int enter(struct session *ses, struct f_data_c *f, int a);
4241 int field_op(struct session *ses, struct f_data_c *f, struct link *l, struct links_event *ev);
4242
4243 int can_open_in_new(struct terminal *);
4244 void open_in_new_window(struct terminal *, void *fn_, void *ses_);
4245 extern void (* const send_open_new_xterm_ptr)(struct terminal *, void *fn_, void *ses_);
4246 void destroy_fc(struct form_control *);
4247 void sort_links(struct f_data *);
4248 void free_format_text_cache_entry(struct form_state *fs);
4249 struct view_state *create_vs(void);
4250 void destroy_vs(struct view_state *);
4251 int dump_to_file(struct f_data *, int);
4252 void check_vs(struct f_data_c *);
4253 void draw_doc(struct terminal *t, void *scr_);
4254 void draw_formatted(struct session *);
4255 void draw_fd(struct f_data_c *);
4256 void next_frame(struct session *, int);
4257 void send_event(struct session *, struct links_event *);
4258 void link_menu(struct terminal *, void *, void *);
4259 void save_as(struct terminal *, void *, void *);
4260 void save_url(void *, unsigned char *);
4261 void menu_save_formatted(struct terminal *, void *, void *);
4262 void copy_url_location(struct terminal *, void *, void *);
4263 void selected_item(struct terminal *, void *, void *);
4264 void toggle(struct session *, struct f_data_c *, int);
4265 void do_for_frame(struct session *, void (*)(struct session *, struct f_data_c *, int), int);
4266 int get_current_state(struct session *);
4267 unsigned char *print_current_link(struct session *);
4268 unsigned char *print_current_title(struct session *);
4269 void loc_msg(struct terminal *, struct location *, struct f_data_c *);
4270 void state_msg(struct session *);
4271 void head_msg(struct session *);
4272 void search_for(void *, unsigned char *);
4273 void search_for_back(void *, unsigned char *);
4274 void find_next(struct session *, struct f_data_c *, int);
4275 void find_next_back(struct session *, struct f_data_c *, int);
4276 void set_frame(struct session *, struct f_data_c *, int);
4277 struct f_data_c *current_frame(struct session *);
4278 void reset_form(struct f_data_c *f, int form_num);
4279 void set_textarea(struct session *, struct f_data_c *, int);
4280
4281 void copy_js_event_spec(struct js_event_spec **, struct js_event_spec *);
4282 int join_js_event_spec(struct js_event_spec **, struct js_event_spec *);
4283 void free_js_event_spec(struct js_event_spec *);
4284 void create_js_event_spec(struct js_event_spec **);
4285 int compare_js_event_spec(struct js_event_spec *, struct js_event_spec *);
4286 unsigned char *print_js_event_spec(struct js_event_spec *);
4287
4288 /* font_inc.c */
4289
4290 #ifdef G
4291 extern struct letter letter_data[];
4292 extern struct font font_table[];
4293 #endif
4294
4295 /* gif.c */
4296
4297 #ifdef G
4298
4299 void gif_destroy_decoder(struct cached_image *);
4300 void gif_start(struct cached_image *goi);
4301 void gif_restart(unsigned char *data, int length);
4302
4303 void xbm_start(struct cached_image *goi);
4304 void xbm_restart(struct cached_image *goi, unsigned char *data, int length);
4305
4306 #endif
4307
4308 /* png.c */
4309
4310 #ifdef G
4311
4312 void png_start(struct cached_image *cimg);
4313 void png_restart(struct cached_image *cimg, unsigned char *data, int length);
4314 void png_destroy_decoder(struct cached_image *cimg);
4315 void add_png_version(unsigned char **s, int *l);
4316
4317 #endif /* #ifdef G */
4318
4319 /* tiff.c */
4320
4321 #if defined(G) && defined(HAVE_TIFF)
4322
4323 void tiff_start(struct cached_image *cimg);
4324 void tiff_restart(struct cached_image *cimg, unsigned char *data, int length);
4325 void tiff_finish(struct cached_image *cimg);
4326 void tiff_destroy_decoder(struct cached_image *cimg);
4327
4328 void add_tiff_version(unsigned char **s, int *l);
4329
4330 #endif /* #if defined(G) && defined(HAVE_TIFF) */
4331
4332 /* svg.c */
4333
4334 #if defined(G) && defined(HAVE_SVG)
4335
4336 void svg_start(struct cached_image *cimg);
4337 void svg_restart(struct cached_image *cimg, unsigned char *data, int length);
4338 void svg_finish(struct cached_image *cimg);
4339 void svg_destroy_decoder(struct cached_image *cimg);
4340
4341 void add_svg_version(unsigned char **s, int *l);
4342
4343 #endif
4344
4345 /* img.c */
4346
4347 #ifdef G
4348
4349 struct image_description {
4350 unsigned char *url; /* url=completed url */
4351 int xsize, ysize; /* -1 --- unknown size. Space:pixel
4352 space of the screen */
4353 int link_num;
4354 int link_order;
4355 unsigned char *name;
4356 unsigned char *alt;
4357 unsigned char *src; /* reflects the src attribute */
4358 int border, vspace, hspace;
4359 int align;
4360 int ismap;
4361 int insert_flag; /* pokud je 1, ma se vlozit do seznamu obrazku ve f_data */
4362
4363 unsigned char *usemap;
4364 unsigned autoscale_x, autoscale_y; /* Requested autoscale dimensions
4365 (maximum allowed rectangle), 0,0
4366 means turned off. 0,something or
4367 something,0 not allowed. */
4368 };
4369
4370 extern int end_callback_hit;
4371 extern struct cached_image *global_cimg;
4372
4373 /* Below are internal functions shared with imgcache.c, gif.c, and xbm.c */
4374 int header_dimensions_known(struct cached_image *cimg);
4375 void img_end(struct cached_image *cimg);
4376 void compute_background_8(struct cached_image *cimg, unsigned char rgb[3]);
4377 void buffer_to_bitmap_incremental(struct cached_image *cimg, unsigned char *buffer, ssize_t height, ssize_t yoff, int *dregs, int use_strip);
4378
4379 /* Below is external interface provided by img.c */
4380 struct g_part;
4381 int get_foreground(int rgb);
4382 struct g_object_image *insert_image(struct g_part *p, struct image_description *im);
4383 void change_image (struct g_object_image *goi, unsigned char *url, unsigned char *src, struct f_data *fdata);
4384 void img_destruct_cached_image(struct cached_image *img);
4385
4386 #endif
4387
4388 /* jpeg.c */
4389
4390 #if defined(G) && defined(HAVE_JPEG)
4391
4392 /* Functions exported by jpeg.c for higher layers */
4393 void jpeg_start(struct cached_image *cimg);
4394 void jpeg_restart(struct cached_image *cimg, unsigned char *data, int length);
4395 void jpeg_destroy_decoder(struct cached_image *cimg);
4396 void add_jpeg_version(unsigned char **s, int *l);
4397
4398 #endif /* #if defined(G) && defined(HAVE_JPEG) */
4399
4400 int known_image_type(unsigned char *type);
4401
4402 /* imgcache.c */
4403
4404 #ifdef G
4405
4406 void init_imgcache(void);
4407 my_uintptr_t imgcache_info(int type);
4408 struct cached_image *find_cached_image(int bg, unsigned char *url, int xw, int
4409 yw, int xyw_meaning, int scale, unsigned aspect);
4410 void add_image_to_cache(struct cached_image *ci);
4411 void deref_cached_image(struct cached_image *ci);
4412
4413 #endif
4414
4415 /* view_gr.c */
4416
4417 #ifdef G
4418
4419 /* intersection of 2 intervals s=start, l=len (len 0 is empty interval) */
intersect(int s1,int l1,int s2,int l2,int * s3,int * l3)4420 static inline void intersect(int s1, int l1, int s2, int l2, int *s3, int *l3)
4421 {
4422 int e1 = s1 + l1;
4423 int e2 = s2 + l2;
4424 int e3;
4425
4426 if (e1 < s1) { int tmp = s1; s1 = e1; e1 = tmp; }
4427 if (e2 < s2) { int tmp = s2; s2 = e2; e2 = tmp; }
4428
4429 if (!l1 || !l2)
4430 goto intersect_empty;
4431
4432 if (s1 <= s2 && s2 <= e1)
4433 *s3 = s2;
4434 else if (s2 < s1)
4435 *s3 = s1;
4436 else
4437 goto intersect_empty;
4438
4439 if (s1 <= e2 && e2 <= e1)
4440 e3 = e2;
4441 else if (e2 > e1)
4442 e3 = e1;
4443 else
4444 goto intersect_empty;
4445
4446 *l3 = e3 - *s3;
4447 return;
4448
4449 intersect_empty:
4450 *s3 = 0;
4451 *l3 = 0;
4452 }
4453
4454
4455 int g_forward_mouse(struct f_data_c *fd, struct g_object *a, int x, int y, int b);
4456
4457 void draw_vscroll_bar(struct graphics_device *dev, int x, int y, int yw, int total, int view, int pos);
4458 void draw_hscroll_bar(struct graphics_device *dev, int x, int y, int xw, int total, int view, int pos);
4459 void get_scrollbar_pos(int dsize, int total, int vsize, int vpos, int *start, int *end);
4460
4461
4462 void get_parents(struct f_data *f, struct g_object *a);
4463
4464 void g_dummy_mouse(struct f_data_c *, struct g_object *, int, int, int);
4465 void g_text_mouse(struct f_data_c *, struct g_object *, int, int, int);
4466 void g_line_mouse(struct f_data_c *, struct g_object *, int, int, int);
4467 void g_area_mouse(struct f_data_c *, struct g_object *, int, int, int);
4468
4469 void g_dummy_draw(struct f_data_c *, struct g_object *, int, int);
4470 void g_text_draw(struct f_data_c *, struct g_object *, int, int);
4471 void g_line_draw(struct f_data_c *, struct g_object *, int, int);
4472 void g_area_draw(struct f_data_c *, struct g_object *, int, int);
4473
4474 void g_tag_destruct(struct g_object *);
4475 void g_text_destruct(struct g_object *);
4476 void g_line_destruct(struct g_object *);
4477 void g_line_bg_destruct(struct g_object *);
4478 void g_area_destruct(struct g_object *);
4479
4480 void g_line_get_list(struct g_object *, void (*)(struct g_object *parent, struct g_object *child));
4481 void g_area_get_list(struct g_object *, void (*)(struct g_object *parent, struct g_object *child));
4482
4483 void draw_one_object(struct f_data_c *fd, struct g_object *o);
4484 void draw_title(struct f_data_c *f);
4485 void draw_graphical_doc(struct terminal *t, struct f_data_c *scr, int active);
4486 int g_next_link(struct f_data_c *fd, int dir, int do_scroll);
4487 int g_frame_ev(struct session *ses, struct f_data_c *fd, struct links_event *ev);
4488 void g_find_next(struct f_data_c *f, int);
4489
4490 int is_link_in_view(struct f_data_c *fd, int nl);
4491
4492 void init_grview(void);
4493
4494 #endif
4495
4496 /* html.c */
4497
4498 #define AT_BOLD 1
4499 #define AT_ITALIC 2
4500 #define AT_UNDERLINE 4
4501 #define AT_FIXED 8
4502 #define AT_GRAPHICS 16
4503 #define AT_INVERT 32
4504
4505 #define AL_LEFT 0
4506 #define AL_CENTER 1
4507 #define AL_RIGHT 2
4508 #define AL_BLOCK 3
4509 #define AL_NO 4
4510 #define AL_NO_BREAKABLE 5
4511 #define AL_BOTTOM 6
4512 #define AL_MIDDLE 7
4513 #define AL_TOP 8
4514
4515 #define AL_MASK 0x1f
4516
4517 #define AL_NOBRLEXP 0x20
4518 #define AL_MONO 0x40
4519
4520 struct text_attrib_beginning {
4521 int attr;
4522 struct rgb fg;
4523 struct rgb bg;
4524 int fontsize;
4525 int baseline;
4526 };
4527
4528 struct text_attrib {
4529 int attr;
4530 struct rgb fg;
4531 struct rgb bg;
4532 int fontsize;
4533 int baseline;
4534 unsigned char *fontface;
4535 unsigned char *link;
4536 unsigned char *target;
4537 unsigned char *image;
4538 struct js_event_spec *js_event;
4539 struct form_control *form;
4540 struct rgb clink;
4541 unsigned char *href_base;
4542 unsigned char *target_base;
4543 unsigned char *select;
4544 int select_disabled;
4545 };
4546
4547 #define P_NUMBER 1
4548 #define P_alpha 2
4549 #define P_ALPHA 3
4550 #define P_roman 4
4551 #define P_ROMAN 5
4552 #define P_STAR 1
4553 #define P_O 2
4554 #define P_PLUS 3
4555 #define P_LISTMASK 7
4556 #define P_COMPACT 8
4557
4558 struct par_attrib {
4559 int align;
4560 int leftmargin;
4561 int rightmargin;
4562 int width;
4563 int list_level;
4564 unsigned list_number;
4565 int dd_margin;
4566 int flags;
4567 struct rgb bgcolor;
4568 int implicit_pre_wrap;
4569 };
4570
4571 struct html_element {
4572 list_entry_1st
4573 struct text_attrib attr;
4574 struct par_attrib parattr;
4575 #define INVISIBLE 1
4576 #define INVISIBLE_SCRIPT 2
4577 #define INVISIBLE_STYLE 3
4578 int invisible;
4579 unsigned char *name;
4580 int namelen;
4581 unsigned char *options;
4582 int linebreak;
4583 int dontkill;
4584 struct frameset_desc *frameset;
4585 list_entry_last
4586 };
4587
4588 extern int get_attr_val_nl;
4589
4590 extern struct list_head html_stack;
4591 extern int line_breax;
4592
4593 extern int html_format_changed;
4594
4595 extern unsigned char *startf;
4596 extern unsigned char *eofff;
4597
4598 #define html_top_ list_struct(html_stack.next, struct html_element)
4599 #ifndef DEBUG
4600 #define html_top (*html_top_)
4601 #else
empty_html_stack(unsigned char * file,int line)4602 static inline void empty_html_stack(unsigned char *file, int line)
4603 {
4604 errfile = file;
4605 errline = line;
4606 int_error("empty html stack");
4607 }
4608 #define html_top (*(list_empty(html_stack) ? empty_html_stack(cast_uchar __FILE__, __LINE__), html_top_ : html_top_))
4609 #endif
4610 #define format_ (html_top.attr)
4611 #define par_format (html_top.parattr)
4612
4613 extern void *ff;
4614 extern void (*put_chars_f)(void *, unsigned char *, int);
4615 extern void (*line_break_f)(void *);
4616 extern void *(*special_f)(void *, int, ...);
4617
4618 extern int table_level;
4619 extern int empty_format;
4620
4621 extern struct form form;
4622 extern unsigned char *last_form_tag;
4623 extern unsigned char *last_form_attr;
4624 extern unsigned char *last_input_tag;
4625
4626 extern unsigned char *last_link;
4627 extern unsigned char *last_image;
4628 extern unsigned char *last_target;
4629 extern struct form_control *last_form;
4630 extern struct js_event_spec *last_js_event;
4631 extern int js_fun_depth;
4632 extern int js_memory_limit;
4633
4634 int parse_element(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **);
4635 unsigned char *get_attr_val(unsigned char *, unsigned char *);
4636 int has_attr(unsigned char *, unsigned char *);
4637 int get_num(unsigned char *, unsigned char *);
4638 int get_width(unsigned char *, unsigned char *, int);
4639 int get_color(unsigned char *, unsigned char *, struct rgb *);
4640 int get_bgcolor(unsigned char *, struct rgb *);
4641 void html_stack_dup(void);
4642 void kill_html_stack_item(struct html_element *);
4643 int should_skip_script(unsigned char *);
4644 unsigned char *skip_comment(unsigned char *, unsigned char *);
4645 void parse_html(unsigned char *, unsigned char *, void (*)(void *, unsigned char *, int), void (*)(void *), void *(*)(void *, int, ...), void *, unsigned char *);
4646 int get_image_map(unsigned char *, unsigned char *, unsigned char *, unsigned char *a, struct menu_item **, struct memory_list **, unsigned char *, unsigned char *, int, int, int, int gfx);
4647 void scan_http_equiv(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **, unsigned char **, int *, struct js_event_spec **);
4648
4649 int decode_color(unsigned char *, struct rgb *);
4650
4651 #define SP_TAG 0
4652 #define SP_CONTROL 1
4653 #define SP_TABLE 2
4654 #define SP_USED 3
4655 #define SP_FRAMESET 4
4656 #define SP_FRAME 5
4657 #define SP_SCRIPT 6
4658 #define SP_IMAGE 7
4659 #define SP_NOWRAP 8
4660 #define SP_REFRESH 9
4661 #define SP_SET_BASE 10
4662 #define SP_FORCE_BREAK 11
4663 #define SP_HR 12
4664
4665 struct frameset_param {
4666 struct frameset_desc *parent;
4667 int x, y;
4668 int *xw, *yw;
4669 };
4670
4671 #define SCROLLING_NO 0
4672 #define SCROLLING_YES 1
4673 #define SCROLLING_AUTO 2
4674
4675 struct frame_param {
4676 struct frameset_desc *parent;
4677 unsigned char *name;
4678 unsigned char *url;
4679 int marginwidth;
4680 int marginheight;
4681 unsigned char scrolling;
4682 };
4683
4684 struct refresh_param {
4685 unsigned char *url;
4686 int time;
4687 };
4688
4689 struct hr_param {
4690 int size;
4691 int width;
4692 };
4693
4694 void free_menu(struct menu_item *);
4695 void do_select_submenu(struct terminal *, void *, void *);
4696
4697 void clr_white(unsigned char *name);
4698 void clr_spaces(unsigned char *name, int firstlast);
4699
4700 /* html_r.c */
4701
4702 extern int g_ctrl_num;
4703
4704 extern struct conv_table *convert_table;
4705
4706 struct part {
4707 int x, y;
4708 int xp, yp;
4709 int xmax;
4710 int xa;
4711 int cx, cy;
4712 struct f_data *data;
4713 int attribute;
4714 unsigned char *spaces;
4715 int z_spaces;
4716 int spl;
4717 int link_num;
4718 struct list_head uf;
4719 #ifdef ENABLE_UTF8
4720 unsigned char utf8_part[7];
4721 unsigned char utf8_part_len;
4722 #endif
4723 };
4724
4725 #ifdef G
4726 struct g_part {
4727 int x, y;
4728 int xmax;
4729 int cx, cy;
4730 int cx_w;
4731 struct g_object_area *root;
4732 struct g_object_line *line;
4733 struct g_object_text *text;
4734 int pending_text_len;
4735 struct wrap_struct w;
4736 struct style *current_style;
4737 struct f_data *data;
4738 int link_num;
4739 struct list_head uf;
4740 };
4741 #endif
4742
4743 struct sizes {
4744 int xmin, xmax, y;
4745 };
4746
4747 extern struct f_data *current_f_data;
4748
4749 void free_additional_files(struct additional_files **);
4750 void free_frameset_desc(struct frameset_desc *);
4751 struct frameset_desc *copy_frameset_desc(struct frameset_desc *);
4752
4753 struct f_data *init_formatted(struct document_options *);
4754 void destroy_formatted(struct f_data *);
4755
4756 /* d_opt je podle Mikulase nedefinovany mimo html parser, tak to jinde nepouzivejte
4757 *
4758 * -- Brain
4759 */
4760 extern struct document_options dd_opt;
4761 extern struct document_options *d_opt;
4762 extern int margin;
4763
4764 int find_nearest_color(struct rgb *r, int l);
4765 int fg_color(int fg, int bg);
4766
4767 void xxpand_line(struct part *, int, int);
4768 void xxpand_lines(struct part *, int);
4769 void xset_hchar(struct part *, int, int, unsigned, unsigned char);
4770 void xset_hchars(struct part *, int, int, int, unsigned, unsigned char);
4771 void html_tag(struct f_data *, unsigned char *, int, int);
4772 void process_script(struct f_data *, unsigned char *);
4773 void set_base(struct f_data *, unsigned char *);
4774 void html_process_refresh(struct f_data *, unsigned char *, int );
4775
4776 int compare_opt(struct document_options *, struct document_options *);
4777 void copy_opt(struct document_options *, struct document_options *);
4778
4779 struct link *new_link(struct f_data *);
4780 struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *, int);
4781 struct part *format_html_part(unsigned char *, unsigned char *, int, int, int, struct f_data *, int, int, unsigned char *, int);
4782 void really_format_html(struct cache_entry *, unsigned char *, unsigned char *, struct f_data *, int frame);
4783 struct link *get_link_at_location(struct f_data *f, int x, int y);
4784 int get_search_data(struct f_data *);
4785
4786 struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param *fp);
4787 void create_frame(struct frame_param *fp);
4788
4789 /* html_gr.c */
4790
4791 #ifdef G
4792
4793 void release_image_map(struct image_map *map);
4794 int is_in_area(struct map_area *a, int x, int y);
4795
4796 struct background *g_get_background(unsigned char *bg, unsigned char *bgcolor);
4797 void g_release_background(struct background *bg);
4798 void g_draw_background(struct graphics_device *dev, struct background *bg, int x, int y, int xw, int yw);
4799
4800 void g_x_extend_area(struct g_object_area *a, int width, int height, int align);
4801 struct g_part *g_format_html_part(unsigned char *, unsigned char *, int, int, int, unsigned char *, int, unsigned char *, unsigned char *, struct f_data *);
4802 void g_release_part(struct g_part *);
4803 int g_get_area_width(struct g_object_area *o);
4804 void add_object(struct g_part *pp, struct g_object *o);
4805 void add_object_to_line(struct g_part *pp, struct g_object_line **lp,
4806 struct g_object *go);
4807 void flush_pending_text_to_line(struct g_part *p);
4808 void flush_pending_line_to_obj(struct g_part *p, int minheight);
4809
4810 #endif
4811
4812 /* html_tbl.c */
4813
4814 unsigned char *skip_element(unsigned char *, unsigned char *, unsigned char *, int);
4815 void format_table(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);
4816 void table_bg(struct text_attrib *ta, unsigned char bgstr[8]);
4817
4818 void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num);
4819 void add_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num, void *p);
4820
4821 /* default.c */
4822
4823 extern int ggr;
4824 extern int force_g;
4825 extern unsigned char ggr_drv[MAX_STR_LEN];
4826 extern unsigned char ggr_mode[MAX_STR_LEN];
4827 extern unsigned char ggr_display[MAX_STR_LEN];
4828
4829 extern unsigned char default_target[MAX_STR_LEN];
4830
4831 unsigned char *parse_options(int, char *[]);
4832 void init_home(void);
4833 unsigned char *get_token(unsigned char **line);
4834 void add_quoted_to_str(unsigned char **s, int *l, unsigned char *q);
4835 unsigned char *read_config_file(unsigned char *);
4836 void delete_config_file(unsigned char *);
4837 int write_to_config_file(unsigned char *, unsigned char *, int);
4838 void load_config(void);
4839 void write_config(struct terminal *);
4840 void write_html_config(struct terminal *);
4841 void end_config(void);
4842
4843 void load_url_history(void);
4844 void save_url_history(void);
4845
4846 struct driver_param {
4847 list_entry_1st
4848 int kbd_codepage;
4849 int palette_mode;
4850 unsigned char *param;
4851 unsigned char shell_term[MAX_STR_LEN];
4852 int nosave;
4853 list_entry_last
4854 unsigned char name[1];
4855 };
4856 /* -if exec is NULL, shell_term is unused
4857 -otherwise this string describes shell to be executed by the
4858 exec function, the '%' char means string to be executed
4859 -shell cannot be NULL
4860 -if exec is !NULL and shell is empty, exec should use some
4861 default shell (e.g. "xterm -e %")
4862 */
4863
4864 struct driver_param *get_driver_param(unsigned char *);
4865
4866 extern int anonymous;
4867
4868 extern unsigned char system_name[];
4869 extern unsigned char compiler_name[];
4870
4871 extern unsigned char *links_home;
4872 extern int first_use;
4873
4874 extern int disable_libevent;
4875 extern int disable_openmp;
4876 extern int no_connect;
4877 extern int base_session;
4878 #define D_DUMP 1
4879 #define D_SOURCE 2
4880 extern int dmp;
4881 extern int screen_width;
4882 extern int dump_codepage;
4883 extern int force_html;
4884
4885 extern int max_connections;
4886 extern int max_connections_to_host;
4887 extern int max_tries;
4888 extern int receive_timeout;
4889 extern int unrestartable_receive_timeout;
4890 extern int timeout_multiple_addresses;
4891 extern unsigned char bind_ip_address[16];
4892 extern unsigned char bind_ipv6_address[INET6_ADDRSTRLEN];
4893 extern int async_lookup;
4894 extern int download_utime;
4895
4896 extern int max_format_cache_entries;
4897 extern int memory_cache_size;
4898 extern int image_cache_size;
4899 extern int font_cache_size;
4900 extern int aggressive_cache;
4901
4902 struct ipv6_options {
4903 int addr_preference;
4904 };
4905
4906 #define ADDR_PREFERENCE_DEFAULT 0
4907 #define ADDR_PREFERENCE_IPV4 1
4908 #define ADDR_PREFERENCE_IPV6 2
4909 #define ADDR_PREFERENCE_IPV4_ONLY 3
4910 #define ADDR_PREFERENCE_IPV6_ONLY 4
4911
4912 extern struct ipv6_options ipv6_options;
4913
4914 #define REFERER_NONE 0
4915 #define REFERER_SAME_URL 1
4916 #define REFERER_FAKE 2
4917 #define REFERER_REAL 3
4918 #define REFERER_REAL_SAME_SERVER 4
4919
4920 struct proxies {
4921 unsigned char http_proxy[MAX_STR_LEN];
4922 unsigned char ftp_proxy[MAX_STR_LEN];
4923 unsigned char https_proxy[MAX_STR_LEN];
4924 unsigned char socks_proxy[MAX_STR_LEN];
4925 unsigned char dns_append[MAX_STR_LEN];
4926 unsigned char no_proxy[MAX_STR_LEN];
4927 int only_proxies;
4928 };
4929
4930 extern struct proxies proxies;
4931
4932 #define SSL_ACCEPT_INVALID_CERTIFICATE 0
4933 #define SSL_WARN_ON_INVALID_CERTIFICATE 1
4934 #define SSL_REJECT_INVALID_CERTIFICATE 2
4935
4936 struct ssl_options {
4937 int certificates;
4938 int built_in_certificates;
4939 unsigned char client_cert_key[MAX_STR_LEN];
4940 unsigned char client_cert_crt[MAX_STR_LEN];
4941 unsigned char client_cert_password[MAX_STR_LEN];
4942 };
4943
4944 extern struct ssl_options ssl_options;
4945
4946 struct http_header_options {
4947 int fake_firefox;
4948 int do_not_track;
4949 int referer;
4950 unsigned char fake_referer[MAX_STR_LEN];
4951 unsigned char fake_useragent[MAX_STR_LEN];
4952 unsigned char extra_header[MAX_STR_LEN];
4953 };
4954
4955 struct http_options {
4956 int http10;
4957 int allow_blacklist;
4958 int no_accept_charset;
4959 int no_compression;
4960 int retry_internal_errors;
4961 struct http_header_options header;
4962 };
4963
4964 extern struct http_options http_options;
4965
4966 struct ftp_options {
4967 unsigned char anon_pass[MAX_STR_LEN];
4968 int passive_ftp;
4969 int eprt_epsv;
4970 int set_tos;
4971 };
4972
4973 extern struct ftp_options ftp_options;
4974
4975 struct smb_options {
4976 int allow_hyperlinks_to_smb;
4977 };
4978
4979 extern struct smb_options smb_options;
4980
4981 extern unsigned char download_dir[];
4982
4983 #define SCRUB_HEADERS (proxies.only_proxies || http_options.header.fake_firefox)
4984
4985 #ifdef JS
4986 extern int js_enable;
4987 extern int js_verbose_errors;
4988 extern int js_verbose_warnings;
4989 extern int js_all_conversions;
4990 extern int js_global_resolve;
4991 #endif
4992
4993 extern double display_red_gamma,display_green_gamma,display_blue_gamma;
4994 extern double user_gamma;
4995 extern double bfu_aspect;
4996 extern int display_optimize; /*0=CRT, 1=LCD RGB, 2=LCD BGR */
4997 extern int dither_letters;
4998 extern int dither_images;
4999 extern int gamma_bits;
5000 extern int overwrite_instead_of_scroll;
5001
5002 extern unsigned char font_file[MAX_STR_LEN];
5003 extern unsigned char font_file_b[MAX_STR_LEN];
5004 extern unsigned char font_file_m[MAX_STR_LEN];
5005 extern unsigned char font_file_m_b[MAX_STR_LEN];
5006
5007 #ifdef USE_ITALIC
5008 extern unsigned char font_file_i[MAX_STR_LEN];
5009 extern unsigned char font_file_i_b[MAX_STR_LEN];
5010 extern unsigned char font_file_i_m[MAX_STR_LEN];
5011 extern unsigned char font_file_i_m_b[MAX_STR_LEN];
5012 #endif
5013
5014
5015 extern int menu_font_size;
5016 extern unsigned G_BFU_FG_COLOR, G_BFU_BG_COLOR, G_SCROLL_BAR_AREA_COLOR, G_SCROLL_BAR_BAR_COLOR, G_SCROLL_BAR_FRAME_COLOR;
5017
5018 extern unsigned char bookmarks_file[MAX_STR_LEN];
5019 extern int bookmarks_codepage;
5020
5021 extern int save_history;
5022
5023 extern int enable_cookies;
5024 extern int save_cookies;
5025 extern double max_cookie_age;
5026
5027 extern struct document_setup dds;
5028
5029 /* regexp.c */
5030
5031 char *regexp_replace(char *, char *, char *);
5032
5033 /* listedit.c */
5034
5035 #define TITLE_EDIT 0
5036 #define TITLE_ADD 1
5037
5038 struct list {
5039 list_entry_1st
5040 unsigned char type;
5041 /*
5042 * bit 0: 0=item, 1=directory
5043 * bit 1: directory is open (1)/closed (0); for item unused
5044 * bit 2: 1=item is selected 0=item is not selected
5045 */
5046 int depth;
5047 struct list *fotr; /* ignored when list is flat */
5048 list_entry_last
5049 };
5050
5051 #ifdef __GNUC__
list_next(struct list * l)5052 static inline struct list *list_next(struct list *l)
5053 {
5054 verify_list_entry(&l->list_entry);
5055 return list_struct(l->list_entry.next, struct list);
5056 }
list_prev(struct list * l)5057 static inline struct list *list_prev(struct list *l)
5058 {
5059 verify_list_entry(&l->list_entry);
5060 return list_struct(l->list_entry.prev, struct list);
5061 }
5062 #else
5063 #define list_next(l) (verify_list_entry(&(l)->list_entry), list_struct((l)->list_entry.next, struct list))
5064 #define list_prev(l) (verify_list_entry(&(l)->list_entry), list_struct((l)->list_entry.prev, struct list))
5065 #endif
5066
5067 #ifndef REORDER_LIST_ENTRIES
5068 #define list_head_1st struct list head;
5069 #define list_head_last
5070 #else
5071 #define list_head_1st
5072 #define list_head_last struct list head;
5073 #endif
5074
5075 struct list_description {
5076 unsigned char type; /* 0=flat, 1=tree */
5077 struct list *list; /* head of the list */
5078 struct list *(*new_item)(void * /* data in internal format */); /* creates new item, does NOT add to the list */
5079 void (*edit_item)(struct dialog_data *, struct list *, void (*)(struct dialog_data *, struct list *, struct list *, struct list_description *) /* ok function */, struct list * /* parameter for the ok_function */, unsigned char); /* must call call delete_item on the item after all */
5080 void *(*default_value)(struct session *, unsigned char /* 0=item, 1=directory */); /* called when add button is pressed, allocates memory, return value is passed to the new_item function, new_item fills the item with this data */
5081 void (*delete_item)(struct list *); /* delete item, if next and prev are not NULL adjusts pointers in the list */
5082 void (*copy_item)(struct list * /* old */, struct list * /* new */); /* gets 2 allocated items, copies all item data except pointers from first item to second one, old data (in second item) will be destroyed */
5083 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 */
5084 struct list *(*find_item)(struct list *start_item, unsigned char *string, int direction /* 1 or -1 */); /* returns pointer to the first item matching given string or NULL if failed. Search starts at start_item including. */
5085 struct history *search_history;
5086 int codepage; /* codepage of all string */
5087 int n_items; /* number of items in main window */
5088
5089 /* following items are string codes */
5090 int item_description; /* e.g. "bookmark" or "extension" ... */
5091 int already_in_use; /* e.g. "Bookmarks window is already open" */
5092 int window_title; /* main window title */
5093 int delete_dialog_title; /* e.g. "Delete bookmark dialog" */
5094 int button; /* when there's no button button_fn is NULL */
5095
5096 void (*button_fn)(struct session *, struct list *); /* gets pointer to the item */
5097 void (*save)(struct session *);
5098
5099 /* internal variables, should not be modified, initially set to 0 */
5100 struct list *current_pos;
5101 struct list *win_offset;
5102 int win_pos;
5103 int open; /* 0=closed, 1=open */
5104 int modified; /* listedit reports 1 when the list was modified by user (and should be e.g. saved) */
5105 struct dialog_data *dlg; /* current dialog, valid only when open==1 */
5106 unsigned char *search_word;
5107 int search_direction;
5108 };
5109
5110 int test_list_window_in_use(struct list_description *ld, struct terminal *term);
5111 int create_list_window(struct list_description *, struct list *, struct terminal *, struct session *);
5112 void reinit_list_window(struct list_description *ld); /* reinitializes list window */
5113
5114
5115 /* types.c */
5116
5117 struct list;
5118
5119 struct assoc {
5120 list_head_1st
5121 unsigned char *label;
5122 unsigned char *ct;
5123 unsigned char *prog;
5124 int cons;
5125 int xwin;
5126 int block;
5127 int ask;
5128 int accept_http;
5129 int accept_ftp;
5130 int system;
5131 list_head_last
5132 };
5133
5134 struct extension {
5135 list_head_1st
5136 unsigned char *ext;
5137 unsigned char *ct;
5138 list_head_last
5139 };
5140
5141 struct protocol_program {
5142 list_entry_1st
5143 unsigned char *prog;
5144 int system;
5145 list_entry_last
5146 };
5147
5148 extern struct list assoc;
5149 extern struct list extensions;
5150
5151 extern struct list_head mailto_prog;
5152 extern struct list_head telnet_prog;
5153 extern struct list_head tn3270_prog;
5154 extern struct list_head mms_prog;
5155 extern struct list_head magnet_prog;
5156
5157 unsigned char *get_compress_by_extension(unsigned char *ext, unsigned char *ext_end);
5158 unsigned char *get_content_type_by_extension(unsigned char *url);
5159 unsigned char *get_content_type(unsigned char *, unsigned char *);
5160 unsigned char *get_content_encoding(unsigned char *head, unsigned char *url, int just_ce);
5161 unsigned char *encoding_2_extension(unsigned char *);
5162 struct assoc *get_type_assoc(struct terminal *term, unsigned char *, int *);
5163 int is_html_type(unsigned char *ct);
5164 unsigned char *get_filename_from_header(unsigned char *head);
5165 unsigned char *get_filename_from_url(unsigned char *, unsigned char *, int);
5166
5167 void menu_assoc_manager(struct terminal *, void *, void *);
5168 void update_assoc(struct assoc *);
5169 void menu_ext_manager(struct terminal *, void *, void *);
5170 void update_ext(struct extension *);
5171 void update_prog(struct list_head *, unsigned char *, int);
5172 unsigned char *get_prog(struct list_head *);
5173 void create_initial_extensions(void);
5174
5175 void free_types(void);
5176
5177 /* block.c */
5178
5179 /* URL blocking calls */
5180 struct block {
5181 list_head_1st
5182 unsigned char *url;
5183 list_head_last
5184 };
5185
5186 extern struct list blocks;
5187 int is_url_blocked(unsigned char* url);
5188 void block_url_query(struct session *ses, unsigned char *u);
5189 void* block_url_add(void *ses_, unsigned char *url);
5190 void block_manager(struct terminal *term, void *fcp, void *ses_);
5191 void init_blocks(void);
5192 void free_blocks(void);
5193
5194 /* bookmark.c */
5195
5196 /* Where all bookmarks are kept */
5197 extern struct list bookmarks;
5198
5199 void finalize_bookmarks(void); /* called, when exiting links */
5200 void init_bookmarks(void); /* called at start */
5201 void reinit_bookmarks(struct session *ses, unsigned char *new_bookmarks_file, int new_bookmarks_codepage);
5202
5203 /* Launches bookmark manager */
5204 void menu_bookmark_manager(struct terminal *, void *, void *);
5205
5206 #endif /* #ifndef LINKS_H */
5207