"Fossies" - the Fresh Open Source Software Archive

Member "links-1.04/links.h" (22 Apr 2018, 66970 Bytes) of package /linux/www/links-1.04.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "links.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.03_vs_1.04.

    1 #include "com-defs.h"
    2 
    3 #ifdef HAVE_CONFIG_H
    4 #include "config.h"
    5 #endif
    6 #ifdef HAVE_CONFIG2_H
    7 #include "config2.h"
    8 #endif
    9 #ifdef HAVE_CONFIG_VMS_H
   10 #include "config-vms.h"
   11 #ifdef __VAX
   12 #undef HAVE_LONG_LONG
   13 #undef HAVE_STRTOLL
   14 #undef HAVE_STRTOQ
   15 #undef HAVE_SOCKETPAIR
   16 #endif
   17 #endif
   18 
   19 #ifndef HAVE_VOLATILE
   20 #define volatile
   21 #endif
   22 
   23 #include "os_dep.h"
   24 #include <stdio.h>
   25 #ifdef HAVE_STDLIB_H
   26 #include <stdlib.h>
   27 #endif
   28 #include <stdarg.h>
   29 #ifdef HAVE_UNISTD_H
   30 #include <unistd.h>
   31 #endif
   32 #ifdef HAVE_STRING_H
   33 #include <string.h>
   34 #endif
   35 #ifdef HAVE_STRINGS_H
   36 #include <strings.h>
   37 #endif
   38 #include <errno.h>
   39 #ifdef HAVE_LIMITS_H
   40 #include <limits.h>
   41 #endif
   42 #include <sys/types.h>
   43 #ifdef HAVE_INTTYPES_H
   44 #include <inttypes.h>
   45 #endif
   46 
   47 #ifndef __USE_XOPEN
   48 #define U_X
   49 #define __USE_XOPEN
   50 #endif
   51 #ifndef _XOPEN_SOURCE
   52 #define X_S
   53 #define _XOPEN_SOURCE   5   /* The 5 is a kludge to get a strptime() prototype in NetBSD */
   54 #endif
   55 #ifdef TIME_WITH_SYS_TIME
   56 #ifdef HAVE_SYS_TIME_H
   57 #include <sys/time.h>
   58 #endif
   59 #ifdef HAVE_TIME_H
   60 #include <time.h>
   61 #endif
   62 #else
   63 #if defined(TM_IN_SYS_TIME) && defined(HAVE_SYS_TIME_H)
   64 #include <sys/time.h>
   65 #elif defined(HAVE_TIME_H)
   66 #include <time.h>
   67 #endif
   68 #endif
   69 #ifdef X_S
   70 #undef _XOPEN_SOURCE
   71 #endif
   72 #ifdef U_X
   73 #undef __USE_XOPEN
   74 #endif
   75 
   76 
   77 #include <sys/stat.h>
   78 #ifdef HAVE_FCNTL_H
   79 #include <fcntl.h>
   80 #endif
   81 #ifdef HAVE_SYS_FILE_H
   82 #include <sys/file.h>
   83 #endif
   84 #ifdef HAVE_DIRENT_H
   85 #include <dirent.h>
   86 #elif defined(HAVE_SYS_NDIR_H)
   87 #include <sys/ndir.h>
   88 #elif defined(HAVE_SYS_DIR_H)
   89 #include <sys/dir.h>
   90 #ifndef dirent
   91 #define dirent direct
   92 #endif
   93 #elif defined(HAVE_NDIR_H)
   94 #include <ndir.h>
   95 #endif
   96 #include <signal.h>
   97 #ifdef HAVE_SYS_WAIT_H
   98 #include <sys/wait.h>
   99 #endif
  100 #ifdef HAVE_SYS_SELECT_H
  101 #include <sys/select.h>
  102 #endif
  103 #ifdef HAVE_SYS_RESOURCE_H
  104 #include <sys/resource.h>
  105 #endif
  106 #ifdef HAVE_SYS_CYGWIN_H
  107 #include <sys/cygwin.h>
  108 #endif
  109 #ifdef HAVE_UWIN_H
  110 #include <uwin.h>
  111 #endif
  112 #ifdef HAVE_INTERIX_INTERIX_H
  113 #include <interix/interix.h>
  114 #endif
  115 #ifdef HAVE_IO_H
  116 #include <io.h>
  117 #endif
  118 #ifdef HAVE_PROCESS_H
  119 #include <process.h>
  120 #endif
  121 #ifdef HAVE_CYGWIN_PROCESS_H
  122 #include <cygwin/process.h>
  123 #endif
  124 #ifdef HAVE_UNIXLIB_H
  125 #include <unixlib.h>
  126 #endif
  127 #ifdef HAVE_SYS_UTSNAME_H
  128 #include <sys/utsname.h>
  129 #endif
  130 #ifdef HAVE_PWD_H
  131 #include <pwd.h>
  132 #endif
  133 #ifdef HAVE_GRP_H
  134 #include <grp.h>
  135 #endif
  136 #ifdef HAVE_MALLOC_H
  137 #include <malloc.h>
  138 #endif
  139 #ifdef HAVE_ALLOCA_H
  140 #include <alloca.h>
  141 #endif
  142 /*
  143 #ifdef HAVE_WAIT_H
  144 #include <wait.h>
  145 #endif
  146 */
  147 
  148 #ifdef HAVE_NETINET_IN_SYSTM_H
  149 #include <netinet/in_systm.h>
  150 #else
  151 #ifdef HAVE_NETINET_IN_SYSTEM_H
  152 #include <netinet/in_system.h>
  153 #endif
  154 #endif
  155 #include <netdb.h>
  156 #include <sys/socket.h>
  157 #include <netinet/in.h>
  158 #ifdef HAVE_NETINET_IP_H
  159 #include <netinet/ip.h>
  160 #endif
  161 #ifdef HAVE_ARPA_INET_H
  162 #include <arpa/inet.h>
  163 #endif
  164 #ifdef HAVE_UTIME_H
  165 #include <utime.h>
  166 #endif
  167 
  168 #ifdef HAVE_TERMIOS_H
  169 #include <termios.h>
  170 #elif defined(HAVE_SGTTY_H)
  171 #include <sgtty.h>
  172 #endif
  173 
  174 #ifdef HAVE_LONG_LONG
  175 #define longlong long long
  176 #define ulonglong unsigned long long
  177 #else
  178 #define longlong double
  179 #define ulonglong double
  180 #endif
  181 
  182 #if defined(__INTERIX) && defined(HAVE_STRTOQ)
  183 extern quad_t
  184 #if defined(__cdecl) || defined(_MSC_VER)
  185 __cdecl
  186 #endif
  187 strtoq(const char *, char **, int);
  188 #endif
  189 
  190 #ifdef HAVE_SSL
  191 #if defined(OPENVMS) && defined(__VAX)
  192 #define OPENSSL_NO_SHA512
  193 #endif
  194 #include <openssl/ssl.h>
  195 #include <openssl/rand.h>
  196 #endif
  197 
  198 #include "os_depx.h"
  199 
  200 #include "setup.h"
  201 
  202 #define LINKS_COPYRIGHT "(C) 1999 - 2017 Mikulas Patocka"
  203 #define LINKS_COPYRIGHT_8859_1 "(C) 1999 - 2017 Mikul\341s Patocka"
  204 #define LINKS_COPYRIGHT_8859_2 "(C) 1999 - 2017 Mikul\341\271 Pato\350ka"
  205 
  206 #ifdef HAVE_POINTER_COMPARISON_BUG
  207 #define DUMMY ((void *)1L)
  208 #else
  209 #define DUMMY ((void *)-1L)
  210 #endif
  211 
  212 #ifdef OPENVMS
  213 #define RET_OK      1   /* SS$_NORMAL */
  214 #define RET_ERROR   3586    /* SS$_LINEABRT */
  215 #define RET_SIGNAL  2096    /* SS$_CANCEL */
  216 #define RET_SYNTAX  20  /* SS$_BADPARAM */
  217 #define RET_FATAL   44  /* SS$_ABORT */
  218 #else
  219 #define RET_OK      0
  220 #define RET_ERROR   1
  221 #define RET_SIGNAL  2
  222 #define RET_SYNTAX  3
  223 #define RET_FATAL   4
  224 #endif
  225 
  226 #ifndef HAVE_RAISE
  227 int raise(int);
  228 #endif
  229 #ifndef HAVE_GETTIMEOFDAY
  230 struct timeval {
  231     long tv_sec;
  232     long tv_usec;
  233 };
  234 struct timezone {
  235     int tz_minuteswest;
  236     int tz_dsttime;
  237 };
  238 int gettimeofday(struct timeval *tv, struct timezone *tz);
  239 #endif
  240 #ifndef HAVE_TEMPNAM
  241 char *tempnam(const char *dir, const char *pfx);
  242 #endif
  243 #ifndef HAVE_STRDUP
  244 char *strdup(const char *s);
  245 #endif
  246 #ifndef HAVE_STRTOL
  247 long strtol(const char *, char **, int);
  248 #endif
  249 #ifndef HAVE_STRTOUL
  250 unsigned long strtoul(const char *, char **, int);
  251 #endif
  252 #ifndef HAVE_STRLEN
  253 size_t strlen(const char *s);
  254 #endif
  255 #ifndef HAVE_STRCPY
  256 char *strcpy(char *dst, const char *src);
  257 #endif
  258 #ifndef HAVE_STRCHR
  259 char *strchr(const char *s, int c);
  260 #endif
  261 #ifndef HAVE_STRRCHR
  262 char *strrchr(const char *s, int c);
  263 #endif
  264 #ifndef HAVE_STRCMP
  265 int strcmp(const char *s1, const char *s2);
  266 #endif
  267 #ifndef HAVE_STRNCMP
  268 int strncmp(const char *s1, const char *s2, size_t n);
  269 #endif
  270 #ifndef HAVE_STRCASECMP
  271 int strcasecmp(const char *s1, const char *s2);
  272 #endif
  273 #ifndef HAVE_STRNCASECMP
  274 int strncasecmp(const char *s1, const char *s2, size_t n);
  275 #endif
  276 #ifndef HAVE_STRCSPN
  277 size_t strcspn(const char *s, const char *reject);
  278 #endif
  279 #ifndef HAVE_STRSPN
  280 size_t strspn(const char *s, const char *accept);
  281 #endif
  282 #ifndef HAVE_STRSTR
  283 char *strstr(const char *haystack, const char *needle);
  284 #endif
  285 #ifndef HAVE_MEMCHR
  286 void *memchr(const void *s, int c, size_t length);
  287 #endif
  288 #ifndef HAVE_MEMCMP
  289 int memcmp(const void *, const void *, size_t);
  290 #endif
  291 #ifndef HAVE_MEMCPY
  292 void *memcpy(void *, const void *, size_t);
  293 #endif
  294 #ifndef HAVE_MEMMOVE
  295 void *memmove(void *, const void *, size_t);
  296 #endif
  297 #ifndef HAVE_MEMSET
  298 void *memset(void *, int, size_t);
  299 #endif
  300 #ifndef HAVE_STRERROR
  301 char *strerror(int);
  302 #endif
  303 
  304 #define EINTRLOOPX(ret_, call_, x_)         \
  305 do {                            \
  306     (ret_) = (call_);               \
  307 } while ((ret_) == (x_) && errno == EINTR)
  308 
  309 #define EINTRLOOP(ret_, call_)  EINTRLOOPX(ret_, call_, -1)
  310 
  311 #define ENULLLOOP(ret_, call_)              \
  312 do {                            \
  313     errno = 0;                  \
  314     (ret_) = (call_);               \
  315 } while (!(ret_) && errno == EINTR)
  316 
  317 #if defined(HAVE_PTHREADS) && defined(HAVE_PTHREAD_SIGMASK)
  318 static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset)
  319 {
  320     int r;
  321     r = pthread_sigmask(how, set, oset);
  322     if (r) {
  323         errno = r;
  324         return -1;
  325     }
  326     return 0;
  327 }
  328 #elif defined(HAVE_SIGPROCMASK)
  329 #define do_sigprocmask  sigprocmask
  330 #else
  331 #ifdef sigset_t
  332 #undef sigset_t
  333 #endif
  334 #define sigset_t    int
  335 #ifndef SIG_BLOCK
  336 #define SIG_BLOCK   0
  337 #endif
  338 #ifndef SIG_SETMASK
  339 #define SIG_SETMASK 2
  340 #endif
  341 static inline int do_sigprocmask(int how, const sigset_t *set, sigset_t *oset) +{
  342     sigset_t old = 0;
  343 #if defined(HAVE_SIGBLOCK) && defined(HAVE_SIGSETMASK)
  344     switch (how) {
  345         case SIG_BLOCK:
  346             old = sigblock(*set);
  347             break;
  348         case SIG_SETMASK:
  349             old = sigsetmask(*set);
  350             break;
  351     }
  352 #endif
  353     if (oset) *oset = old;
  354     return 0;
  355 }
  356 #ifdef sigdelset
  357 #undef sigdelset
  358 #endif
  359 #define sigdelset(x, s)     (*(x) &= ~(1 << (s)), 0)
  360 #ifndef HAVE_SIGDELSET
  361 #define HAVE_SIGDELSET      1
  362 #endif
  363 #ifdef HAVE_SIGFILLSET
  364 #undef HAVE_SIGFILLSET
  365 #endif
  366 #endif
  367 #ifndef HAVE_SIGFILLSET
  368 int sigfillset(sigset_t *set);
  369 #endif
  370 
  371 #define option option_dirty_workaround_for_name_clash_with_include_on_cygwin
  372 #define table table_dirty_workaround_for_name_clash_with_libraries_on_macos
  373 #define scroll scroll_dirty_workaround_for_name_clash_with_libraries_on_macos
  374 #define list list_dirty_workaround_for_name_clash_in_stl_with_class_list
  375 
  376 /* error.c */
  377 
  378 #if defined(DOS)
  379 #define ANSI_BELL       "\007"
  380 #define ANSI_SET_BOLD       ""
  381 #define ANSI_CLEAR_BOLD     ""
  382 #else
  383 #define ANSI_BELL       "\007"
  384 #define ANSI_SET_BOLD       "\033[1m"
  385 #define ANSI_CLEAR_BOLD     "\033[0m"
  386 #endif
  387 
  388 void do_not_optimize_here(void *p);
  389 void check_memory_leaks();
  390 void error(char *, ...) PRINTF_FORMAT(1, 2);
  391 void debug_msg(char *, ...) PRINTF_FORMAT(1, 2);
  392 void int_error(char *, ...) PRINTF_FORMAT(1, 2);
  393 extern int errline;
  394 extern unsigned char *errfile;
  395 
  396 #define internal while (1) errfile = __FILE__, errline = __LINE__, int_error
  397 #define debug errfile = __FILE__, errline = __LINE__, debug_msg
  398 
  399 /* inline */
  400 
  401 #define cast_const_char (const char *)
  402 #define cast_char   (char *)
  403 #define cast_uchar  (unsigned char *)
  404 
  405 void fatal_tty_exit(void);
  406 
  407 #ifdef LEAK_DEBUG
  408 
  409 extern my_uintptr_t mem_amount;
  410 
  411 #ifndef LEAK_DEBUG_LIST
  412 struct alloc_header {
  413     size_t size;
  414 };
  415 #else
  416 struct alloc_header {
  417     struct alloc_header *next;
  418     struct alloc_header *prev;
  419     size_t size;
  420     int line;
  421     unsigned char *file;
  422     unsigned char *comment;
  423 };
  424 #endif
  425 
  426 #define L_D_S ((sizeof(struct alloc_header) + 15) & ~15)
  427 
  428 #endif
  429 
  430 #define overalloc()                         \
  431 do {                                    \
  432     error("ERROR: attempting to allocate too large block at %s:%d", __FILE__, __LINE__);\
  433     fatal_tty_exit();                       \
  434     exit(RET_FATAL);                        \
  435 } while (1) /* while (1) is not a type --- it's here to allow the
  436     compiler that doesn't know that exit doesn't return to do better
  437     optimizations */
  438 
  439 #ifdef LEAK_DEBUG
  440 
  441 void *debug_mem_alloc(unsigned char *, int, size_t);
  442 void debug_mem_free(unsigned char *, int, void *);
  443 void *debug_mem_realloc(unsigned char *, int, void *, size_t);
  444 void set_mem_comment(void *, unsigned char *, int);
  445 
  446 #define mem_alloc(x) debug_mem_alloc(__FILE__, __LINE__, x)
  447 #define mem_free(x) debug_mem_free(__FILE__, __LINE__, x)
  448 #define mem_realloc(x, y) debug_mem_realloc(__FILE__, __LINE__, x, y)
  449 
  450 #else
  451 
  452 static inline void *mem_alloc(size_t size)
  453 {
  454     void *p;
  455     if (!size) return DUMMY;
  456     if (size > MAXINT) overalloc();
  457     if (!(p = malloc(size))) {
  458         error("ERROR: out of memory (malloc returned NULL)");
  459         fatal_tty_exit();
  460         exit(RET_FATAL);
  461         return NULL;
  462     }
  463     return p;
  464 }
  465 
  466 static inline void mem_free(void *p)
  467 {
  468     if (p == DUMMY) return;
  469     if (!p) {
  470         internal("mem_free(NULL)");
  471         return;
  472     }
  473     free(p);
  474 }
  475 
  476 static inline void *mem_realloc(void *p, size_t size)
  477 {
  478     if (p == DUMMY) return mem_alloc(size);
  479     if (!p) {
  480         internal("mem_realloc(NULL, %lu)", (unsigned long)size);
  481         return NULL;
  482     }
  483     if (!size) {
  484         mem_free(p);
  485         return DUMMY;
  486     }
  487     if (size > MAXINT) overalloc();
  488     if (!(p = realloc(p, size))) {
  489         error("ERROR: out of memory (realloc returned NULL)");
  490         fatal_tty_exit();
  491         exit(RET_FATAL);
  492         return NULL;
  493     }
  494     return p;
  495 }
  496 
  497 static inline void *debug_mem_alloc(unsigned char *f, int l, size_t s) { return mem_alloc(s); }
  498 static inline void debug_mem_free(unsigned char *f, int l, void *p) { mem_free(p); }
  499 static inline void *debug_mem_realloc(unsigned char *f, int l, void *p, size_t s) { return mem_realloc(p, s); }
  500 static inline void set_mem_comment(void *p, unsigned char *c, int l) {}
  501 
  502 #endif
  503 
  504 #define mem_alloc_mayfail   mem_alloc
  505 #define mem_realloc_mayfail mem_realloc
  506 
  507 static inline unsigned char upcase(unsigned char a)
  508 {
  509     if (a >= 'a' && a <= 'z') a -= 0x20;
  510     return a;
  511 }
  512 
  513 static inline int xstrcmp(unsigned char *s1, unsigned char *s2)
  514 {
  515     if (!s1 && !s2) return 0;
  516     if (!s1) return -1;
  517     if (!s2) return 1;
  518     return strcmp(s1, s2);
  519 }
  520 
  521 static inline int cmpbeg(unsigned char *str, unsigned char *b)
  522 {
  523     while (*str && upcase(*str) == upcase(*b)) str++, b++;
  524     return !!*b;
  525 }
  526 
  527 #if !(defined(LEAK_DEBUG) && defined(LEAK_DEBUG_LIST))
  528 
  529 static inline unsigned char *memacpy(const unsigned char *src, size_t len)
  530 {
  531     unsigned char *m;
  532     if (!(len + 1)) overalloc();
  533     m = mem_alloc(len + 1);
  534     memcpy(m, src, len);
  535     m[len] = 0;
  536     return m;
  537 }
  538 
  539 static inline unsigned char *stracpy(const unsigned char *src)
  540 {
  541     return src ? memacpy(src, src != DUMMY ? strlen(src) : 0) : NULL;
  542 }
  543 
  544 #else
  545 
  546 static inline unsigned char *debug_memacpy(unsigned char *f, int l, unsigned char *src, size_t len)
  547 {
  548     unsigned char *m;
  549     m = debug_mem_alloc(f, l, len + 1);
  550     memcpy(m, src, len);
  551     m[len] = 0;
  552     return m;
  553 }
  554 
  555 #define memacpy(s, l) debug_memacpy(__FILE__, __LINE__, s, l)
  556 
  557 static inline unsigned char *debug_stracpy(unsigned char *f, int l, unsigned char *src)
  558 {
  559     return src ? debug_memacpy(f, l, src, src != DUMMY ? strlen(src) : 0) : NULL;
  560 }
  561 
  562 #define stracpy(s) debug_stracpy(__FILE__, __LINE__, s)
  563 
  564 #endif
  565 
  566 
  567 static inline int snprint(unsigned char *s, int n, my_uintptr_t num)
  568 {
  569     my_uintptr_t q = 1;
  570     while (q <= num / 10) q *= 10;
  571     while (n-- > 1 && q) {
  572         *(s++) = num / q + '0';
  573         num %= q;
  574 #ifdef __DECC_VER
  575         do_not_optimize_here(&q);   /* compiler bug */
  576 #endif
  577         q /= 10;
  578     }
  579     *s = 0;
  580     return !!q;
  581 }
  582 
  583 static inline int snzprint(unsigned char *s, int n, off_t num)
  584 {
  585     off_t q = 1;
  586     if (n > 1 && num < 0) *(s++) = '-', num = -num, n--;
  587     while (q <= num / 10) q *= 10;
  588     while (n-- > 1 && q) {
  589         *(s++) = num / q + '0';
  590         num %= q;
  591 #ifdef __DECC_VER
  592         do_not_optimize_here(&q);   /* compiler bug */
  593 #endif
  594         q /= 10;
  595     }
  596     *s = 0;
  597     return !!q;
  598 }
  599 
  600 static inline void add_to_strn(unsigned char **s, unsigned char *a)
  601 {
  602     unsigned char *p;
  603     size_t l1 = strlen(*s), l2 = strlen(a);
  604     if (((l1 | l2) | (l1 + l2 + 1)) > MAXINT) overalloc();
  605     p = mem_realloc(*s, l1 + l2 + 1);
  606     strcat(p, a);
  607     *s = p;
  608 }
  609 
  610 #define ALLOC_GR    0x040       /* must be power of 2 */
  611 
  612 #define init_str() init_str_x(__FILE__, __LINE__)
  613 
  614 static inline unsigned char *init_str_x(unsigned char *file, int line)
  615 {
  616     unsigned char *s = debug_mem_alloc(file, line, ALLOC_GR);
  617     *s = 0;
  618     return s;
  619 }
  620 
  621 static inline void add_to_str(unsigned char **s, int *l, unsigned char *a)
  622 {
  623     unsigned char *p;
  624     size_t ll = strlen(a);
  625     if (ll >= MAXINT || *l + ll >= MAXINT) overalloc();
  626     p = *s;
  627     if (((size_t)*l & ~(ALLOC_GR - 1)) != ((*l + ll) & ~(ALLOC_GR - 1))) {
  628         p = *s = mem_realloc(*s, (*l + ll + ALLOC_GR) & ~(ALLOC_GR - 1));
  629     }
  630     strcpy(p + *l, a); *l += ll;
  631 }
  632 
  633 static inline void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, int ll)
  634 {
  635     unsigned char *p;
  636     if (ll < 0 || (size_t)*l + ll >= MAXINT) overalloc();
  637     p = *s;
  638     if ((*l & ~(ALLOC_GR - 1)) != ((*l + ll) & ~(ALLOC_GR - 1))) {
  639         p = *s = mem_realloc(*s, (*l + ll + ALLOC_GR) & ~(ALLOC_GR - 1));
  640     }
  641     memcpy(p + *l, a, ll); p[*l += ll] = 0;
  642 }
  643 
  644 static inline void add_chr_to_str(unsigned char **s, int *l, unsigned char a)
  645 {
  646     unsigned char *p;
  647     if ((size_t)*l + 1 >= MAXINT) overalloc();
  648     p = *s;
  649     if ((*l & (ALLOC_GR - 1)) == ALLOC_GR - 1) {
  650         p = *s = mem_realloc(*s, (*l + 1 + ALLOC_GR) & ~(ALLOC_GR - 1));
  651     }
  652     *(p + *l) = a; *(p + ++(*l)) = 0;
  653 }
  654 
  655 static inline void add_unsigned_long_num_to_str(unsigned char **s, int *l, my_uintptr_t n)
  656 {
  657     unsigned char a[64];
  658     snprint(a, 64, n);
  659     add_to_str(s, l, a);
  660 }
  661 
  662 static inline void add_num_to_str(unsigned char **s, int *l, off_t n)
  663 {
  664     unsigned char a[64];
  665     snzprint(a, 64, n);
  666     add_to_str(s, l, a);
  667 }
  668 
  669 static inline void add_knum_to_str(unsigned char **s, int *l, int n)
  670 {
  671     unsigned char a[13];
  672     if (n && n / (1024 * 1024) * (1024 * 1024) == n) snzprint(a, 12, n / (1024 * 1024)), strcat(a, "M");
  673     else if (n && n / 1024 * 1024 == n) snzprint(a, 12, n / 1024), strcat(a, "k");
  674     else snzprint(a, 13, n);
  675     add_to_str(s, l, a);
  676 }
  677 
  678 static inline long strtolx(unsigned char *c, unsigned char **end)
  679 {
  680     long l;
  681     if (c[0] == '0' && upcase(c[1]) == 'X' && c[2]) l = strtol((char *)c + 2, (char **)end, 16);
  682     else l = strtol((char *)c, (char **)end, 10);
  683     if (!*end) return l;
  684     if (upcase(**end) == 'K') {
  685         (*end)++;
  686         if (l < -MAXINT / 1024) return -MAXINT;
  687         if (l > MAXINT / 1024) return MAXINT;
  688         return l * 1024;
  689     }
  690     if (upcase(**end) == 'M') {
  691         (*end)++;
  692         if (l < -MAXINT / (1024 * 1024)) return -MAXINT;
  693         if (l > MAXINT / (1024 * 1024)) return MAXINT;
  694         return l * (1024 * 1024);
  695     }
  696     return l;
  697 }
  698 
  699 #if defined(HAVE_STRTOLL) || defined(HAVE_STRTOQ) || defined(HAVE_STRTOIMAX)
  700 #define my_strtoll_t    longlong
  701 #else
  702 #define my_strtoll_t    long
  703 #endif
  704 
  705 static inline my_strtoll_t my_strtoll(unsigned char *string, unsigned char **end)
  706 {
  707     my_strtoll_t f;
  708     errno = 0;
  709 #if defined(HAVE_STRTOLL)
  710     f = strtoll(cast_const_char string, (char **)(void *)end, 10);
  711 #elif defined(HAVE_STRTOQ)
  712     f = strtoq(cast_const_char string, (char **)(void *)end, 10);
  713 #elif defined(HAVE_STRTOIMAX)
  714     f = strtoimax(cast_const_char string, (char **)(void *)end, 10);
  715 #else
  716     f = strtol(cast_const_char string, (char **)(void *)end, 10);
  717 #endif
  718     if (f < 0 || errno) return -1;
  719     return f;
  720 }
  721 
  722 /* Copies at most dst_size chars into dst. Ensures null termination of dst. */
  723 static inline unsigned char *safe_strncpy(unsigned char *dst, const unsigned char *src, size_t dst_size)
  724 {
  725     size_t to_copy;
  726     if (!dst_size) return dst;
  727     to_copy = strlen(src);
  728     if (to_copy >= dst_size) to_copy = dst_size - 1;
  729     memcpy(dst, src, to_copy);
  730     memset(dst + to_copy, 0, dst_size - to_copy);
  731     return dst;
  732 }
  733 
  734 
  735 struct list_head {
  736     void *next;
  737     void *prev;
  738 };
  739 
  740 struct xlist_head {
  741     struct xlist_head *next;
  742     struct xlist_head *prev;
  743 };
  744 
  745 #define init_list(x) {do_not_optimize_here(&x); (x).next=&(x); (x).prev=&(x); do_not_optimize_here(&x);}
  746 #define list_empty(x) ((x).next == &(x))
  747 #define del_from_list(x) {do_not_optimize_here(x); ((struct list_head *)(x)->next)->prev=(x)->prev; ((struct list_head *)(x)->prev)->next=(x)->next; do_not_optimize_here(x);}
  748 /*#define add_to_list(l,x) {(x)->next=(l).next; (x)->prev=(typeof(x))&(l); (l).next=(x); if ((l).prev==&(l)) (l).prev=(x);}*/
  749 
  750 #if defined(HAVE_TYPEOF) && !(defined(__GNUC__) && __GNUC__ >= 4)
  751 /* GCC 4 emits warnings about this and I haven't found a way to stop it */
  752 #define add_at_pos(p,x) do {do_not_optimize_here(p); (x)->next=(p)->next; (x)->prev=(p); (p)->next=(x); (x)->next->prev=(x);do_not_optimize_here(p);} while(0)
  753 #define add_to_list(l,x) add_at_pos((typeof(x))(void *)&(l),(x))
  754 #define foreach(e,l) for ((e)=(l).next; (e)!=(typeof(e))(void *)&(l); (e)=(e)->next)
  755 #define foreachback(e,l) for ((e)=(l).prev; (e)!=(typeof(e))(void *)&(l); (e)=(e)->prev)
  756 #else
  757 #define add_at_pos(p,x) do {do_not_optimize_here(p); (x)->next=(p)->next; (x)->prev=(void *)(p); (p)->next=(x); (x)->next->prev=(x); do_not_optimize_here(p); } while(0)
  758 #define add_to_list(l,x) add_at_pos(&(l),(x))
  759 #define foreach(e,l) for ((e)=(l).next; (e)!=(void *)&(l); (e)=(e)->next)
  760 #define foreachback(e,l) for ((e)=(l).prev; (e)!=(void *)&(l); (e)=(e)->prev)
  761 #endif
  762 #define free_list(l) {struct xlist_head *a__;do_not_optimize_here(&l);foreach(a__,l) do_not_optimize_here(a__);foreachback(a__,l) do_not_optimize_here(a__); while ((l).next != &(l)) {a__=(l).next; del_from_list(a__); mem_free(a__); } do_not_optimize_here(&l);}
  763 
  764 #define WHITECHAR(x) ((x) == 9 || (x) == 10 || (x) == 12 || (x) == 13 || (x) == ' ')
  765 #define U(x) ((x) == '"' || (x) == '\'')
  766 
  767 static inline int isA(unsigned char c)
  768 {
  769     return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
  770         c == '_' || c == '-';
  771 }
  772 
  773 static inline int casecmp(unsigned char *c1, unsigned char *c2, size_t len)
  774 {
  775     size_t i;
  776     for (i = 0; i < len; i++) if (upcase(c1[i]) != upcase(c2[i])) return 1;
  777     return 0;
  778 }
  779 
  780 static inline int can_write(int fd)
  781 {
  782     fd_set fds;
  783     struct timeval tv = {0, 0};
  784     int rs;
  785     FD_ZERO(&fds);
  786     if (fd < 0)
  787         internal("can_write: handle %d", fd);
  788     if (fd >= (int)FD_SETSIZE) {
  789         error("too big handle %d", fd);
  790         fatal_tty_exit();
  791         exit(RET_FATAL);
  792     }
  793     FD_SET(fd, &fds);
  794     EINTRLOOP(rs, select(fd + 1, NULL, &fds, NULL, &tv));
  795     if (rs < 0) {
  796         error("ERROR: select for write failed: %s", strerror(errno));
  797         fatal_tty_exit();
  798         exit(RET_FATAL);
  799     }
  800     return rs;
  801 }
  802 
  803 static inline int can_read_timeout(int fd, int sec)
  804 {
  805     fd_set fds;
  806     struct timeval tv;
  807     int rs;
  808     tv.tv_sec = sec;
  809     tv.tv_usec = 0;
  810     FD_ZERO(&fds);
  811     if (fd < 0)
  812         internal("can_read: handle %d", fd);
  813     if (fd >= (int)FD_SETSIZE) {
  814         error("too big handle %d", fd);
  815         fatal_tty_exit();
  816         exit(RET_FATAL);
  817     }
  818     FD_SET(fd, &fds);
  819     EINTRLOOP(rs, select(fd + 1, &fds, NULL, NULL, &tv));
  820     if (rs < 0) {
  821         error("ERROR: select for read failed: %s", strerror(errno));
  822         fatal_tty_exit();
  823         exit(RET_FATAL);
  824     }
  825     return rs;
  826 }
  827 
  828 static inline int can_read(int fd)
  829 {
  830     return can_read_timeout(fd, 0);
  831 }
  832 
  833 #define CI_BYTES    1
  834 #define CI_FILES    2
  835 #define CI_LOCKED   3
  836 #define CI_LOADING  4
  837 #define CI_TIMERS   5
  838 #define CI_TRANSFER 6
  839 #define CI_CONNECTING   7
  840 #define CI_KEEP     8
  841 #define CI_LIST     9
  842 
  843 /* os_dep.c */
  844 
  845 #if defined(HAVE_GPM_H) && defined(HAVE_LIBGPM)
  846 #define USE_GPM
  847 #endif
  848 
  849 struct terminal;
  850 
  851 struct open_in_new {
  852     unsigned char *text;
  853     unsigned char *hk;
  854     void (*fn)(struct terminal *term, unsigned char *, unsigned char *);
  855 };
  856 
  857 void close_fork_tty();
  858 int get_system_env();
  859 int is_twterm();
  860 int is_screen();
  861 int is_xterm();
  862 int get_terminal_size(int, int *, int *);
  863 void handle_terminal_resize(int, void (*)());
  864 void unhandle_terminal_resize(int);
  865 void set_bin(int);
  866 int c_pipe(int *);
  867 void set_nonblock(int);
  868 int get_input_handle();
  869 int get_output_handle();
  870 int get_ctl_handle();
  871 #ifdef OS_SETRAW
  872 int setraw(int ctl, int save);
  873 void setcooked(int ctl);
  874 #endif
  875 void want_draw();
  876 void done_draw();
  877 void terminate_osdep();
  878 void *handle_mouse(int, void (*)(void *, unsigned char *, int), void *);
  879 void unhandle_mouse(void *);
  880 void add_gpm_version(unsigned char **s, int *l);
  881 #ifdef OPENVMS
  882 extern int vms_thread_high_priority;
  883 #endif
  884 int start_thread(void (*)(void *, int), void *, int);
  885 unsigned char *get_clipboard_text();
  886 void set_clipboard_text(unsigned char *);
  887 void set_window_title(unsigned char *);
  888 unsigned char *get_window_title();
  889 int is_safe_in_shell(unsigned char);
  890 unsigned char *escape_path(unsigned char *);
  891 void check_shell_security(unsigned char **);
  892 void check_filename(unsigned char **);
  893 int check_shell_url(unsigned char *);
  894 void do_signal(int sig, void (*handler)(int));
  895 void ignore_signals(void);
  896 void block_stdin();
  897 void unblock_stdin();
  898 void init_os(void);
  899 void init_os_terminal(void);
  900 void get_path_to_exe(void);
  901 int os_get_system_name(unsigned char *buffer);
  902 unsigned char *os_conv_to_external_path(unsigned char *, unsigned char *);
  903 unsigned char *os_fixup_external_program(unsigned char *);
  904 int exe(unsigned char *);
  905 int resize_window(int, int);
  906 int can_resize_window(struct terminal *);
  907 int can_open_os_shell(int);
  908 struct open_in_new *get_open_in_new(int);
  909 void set_highpri();
  910 #ifdef HAVE_OPEN_PREALLOC
  911 int can_prealloc(unsigned char *);
  912 int open_prealloc(unsigned char *, int, int, off_t);
  913 void prealloc_truncate(int, off_t);
  914 #else
  915 static inline void prealloc_truncate(int x, off_t y) {}
  916 #endif
  917 
  918 /* select.c */
  919 
  920 #ifndef FD_SETSIZE
  921 #define FD_SETSIZE  (sizeof(fd_set) * 8)
  922 #endif
  923 
  924 #define NBIT(p)     (sizeof((p)->fds_bits[0]) * 8)
  925 
  926 #ifndef FD_SET
  927 #define FD_SET(n, p)    ((p)->fds_bits[(n)/NBIT(p)] |= (1 << ((n) % NBIT(p))))
  928 #endif
  929 #ifndef FD_CLR
  930 #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NBIT(p)] &= ~(1 << ((n) % NBIT(p))))
  931 #endif
  932 #ifndef FD_ISSET
  933 #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NBIT(p)] & (1 << ((n) % NBIT(p))))
  934 #endif
  935 #ifndef FD_ZERO
  936 #define FD_ZERO(p)  memset((void *)(p), 0, sizeof(*(p)))
  937 #endif
  938 
  939 #ifdef HAVE_LONG_LONG
  940 typedef long long ttime;
  941 typedef unsigned long long uttime;
  942 typedef unsigned long long tcount;
  943 #else
  944 typedef long ttime;
  945 typedef unsigned long uttime;
  946 typedef unsigned long tcount;
  947 #endif
  948 
  949 extern int terminate_loop;
  950 
  951 unsigned long select_info(int);
  952 void select_loop(void (*)());
  953 void register_bottom_half(void (*)(void *), void *);
  954 void unregister_bottom_half(void (*)(void *), void *);
  955 void check_bottom_halves();
  956 int install_timer(ttime, void (*)(void *), void *);
  957 void kill_timer(int);
  958 ttime get_time();
  959 void portable_sleep(unsigned msec);
  960 
  961 #define H_READ  0
  962 #define H_WRITE 1
  963 #define H_ERROR 2
  964 #define H_DATA  3
  965 
  966 void *get_handler(int, int);
  967 void set_handlers(int, void (*)(void *), void (*)(void *), void (*)(void *), void *);
  968 void clear_events(int, int);
  969 void install_signal_handler(int, void (*)(void *), void *, int);
  970 void interruptible_signal(int sig, int in);
  971 void block_signals(int except1, int except2);
  972 void unblock_signals(void);
  973 void set_sigcld();
  974 
  975 /* dns.c */
  976 
  977 typedef unsigned ip;
  978 
  979 int do_real_lookup(unsigned char *, ip *);
  980 void shrink_dns_cache(int);
  981 int find_host(unsigned char *, ip *, void **, void (*)(void *, int), void *);
  982 int find_host_no_cache(unsigned char *, ip *, void **, void (*)(void *, int), void *);
  983 void kill_dns_request(void **);
  984 
  985 /* cache.c */
  986 
  987 struct cache_entry {
  988     struct cache_entry *next;
  989     struct cache_entry *prev;
  990     unsigned char *url;
  991     unsigned char *head;
  992     unsigned char *redirect;
  993     int redirect_get;
  994     off_t length;
  995     off_t max_length;
  996     int incomplete;
  997     int tgc;
  998     unsigned char *last_modified;
  999     off_t data_size;
 1000     struct list_head frag;
 1001     tcount count;
 1002     int refcount;
 1003 #ifdef HAVE_SSL
 1004     unsigned char *ssl_info;
 1005 #endif
 1006 };
 1007 
 1008 struct fragment {
 1009     struct fragment *next;
 1010     struct fragment *prev;
 1011     off_t offset;
 1012     off_t length;
 1013     off_t real_length;
 1014     unsigned char data[1];
 1015 };
 1016 
 1017 extern int page_size;
 1018 
 1019 void init_cache();
 1020 my_uintptr_t cache_info(int);
 1021 int find_in_cache(unsigned char *, struct cache_entry **);
 1022 int get_cache_entry(unsigned char *, struct cache_entry **);
 1023 int add_fragment(struct cache_entry *, off_t, unsigned char *, off_t);
 1024 void defrag_entry(struct cache_entry *);
 1025 void truncate_entry(struct cache_entry *, off_t, int);
 1026 void free_entry_to(struct cache_entry *, off_t);
 1027 void delete_entry_content(struct cache_entry *);
 1028 void delete_cache_entry(struct cache_entry *);
 1029 void garbage_collection(int);
 1030 
 1031 /* sched.c */
 1032 
 1033 #define PRI_MAIN    0
 1034 #define PRI_DOWNLOAD    0
 1035 #define PRI_FRAME   1
 1036 #define PRI_NEED_IMG    2
 1037 #define PRI_IMG     3
 1038 #define PRI_PRELOAD 4
 1039 #define PRI_CANCEL  5
 1040 #define N_PRI       6
 1041 
 1042 struct remaining_info {
 1043     int valid;
 1044     off_t size, loaded, last_loaded, cur_loaded;
 1045     off_t pos;
 1046     ttime elapsed;
 1047     ttime last_time;
 1048     ttime dis_b;
 1049     off_t data_in_secs[CURRENT_SPD_SEC];
 1050     int timer;
 1051 };
 1052 
 1053 struct connection {
 1054     struct connection *next;
 1055     struct connection *prev;
 1056     tcount count;
 1057     unsigned char *url;
 1058     int running;
 1059     int state;
 1060     int prev_error;
 1061     off_t from;
 1062     int pri[N_PRI];
 1063     int no_cache;
 1064     int sock1;
 1065     int sock2;
 1066     void *dnsquery;
 1067     pid_t pid;
 1068     int tries;
 1069     tcount netcfg_stamp;
 1070     struct list_head statuss;
 1071     void *info;
 1072     void *buffer;
 1073     struct conn_info *newconn;
 1074     void (*conn_func)(void *);
 1075     struct cache_entry *cache;
 1076     off_t received;
 1077     off_t est_length;
 1078     int unrestartable;
 1079     struct remaining_info prg;
 1080     int timer;
 1081     int detached;
 1082 #ifdef HAVE_SSL
 1083     SSL *ssl;
 1084     int no_tls;
 1085 #endif
 1086 };
 1087 
 1088 extern tcount netcfg_stamp;
 1089 
 1090 extern struct list_head queue;
 1091 
 1092 struct k_conn {
 1093     struct k_conn *next;
 1094     struct k_conn *prev;
 1095     void (*protocol)(struct connection *);
 1096     unsigned char *host;
 1097     int port;
 1098     int conn;
 1099     ttime timeout;
 1100     ttime add_time;
 1101     int protocol_data;
 1102 };
 1103 
 1104 extern struct list_head keepalive_connections;
 1105 
 1106 static inline int getpri(struct connection *c)
 1107 {
 1108     int i;
 1109     for (i = 0; i < N_PRI; i++) if (c->pri[i]) return i;
 1110     internal("connection has no owner");
 1111     return N_PRI;
 1112 }
 1113 
 1114 #define NC_ALWAYS_CACHE 0
 1115 #define NC_CACHE    1
 1116 #define NC_IF_MOD   2
 1117 #define NC_RELOAD   3
 1118 #define NC_PR_NO_CACHE  4
 1119 
 1120 #define S_WAIT      0
 1121 #define S_DNS       1
 1122 #define S_CONN      2
 1123 #define S_SSL_NEG   3
 1124 #define S_SENT      4
 1125 #define S_LOGIN     5
 1126 #define S_GETH      6
 1127 #define S_PROC      7
 1128 #define S_TRANS     8
 1129 
 1130 #define S__OK           (-2000000000)
 1131 #define S_INTERRUPTED       (-2000000001)
 1132 #define S_EXCEPT        (-2000000002)
 1133 #define S_INTERNAL      (-2000000003)
 1134 #define S_OUT_OF_MEM        (-2000000004)
 1135 #define S_NO_DNS        (-2000000005)
 1136 #define S_CANT_WRITE        (-2000000006)
 1137 #define S_CANT_READ     (-2000000007)
 1138 #define S_MODIFIED      (-2000000008)
 1139 #define S_BAD_URL       (-2000000009)
 1140 #define S_TIMEOUT       (-2000000010)
 1141 #define S_RESTART       (-2000000011)
 1142 #define S_STATE         (-2000000012)
 1143 #define S_LARGE_FILE        (-2000000014)
 1144 
 1145 #define S_HTTP_ERROR        (-2000000100)
 1146 #define S_HTTP_100      (-2000000101)
 1147 #define S_HTTP_204      (-2000000102)
 1148 
 1149 #define S_FILE_TYPE     (-2000000200)
 1150 #define S_FILE_ERROR        (-2000000201)
 1151 
 1152 #define S_FTP_ERROR     (-2000000300)
 1153 #define S_FTP_UNAVAIL       (-2000000301)
 1154 #define S_FTP_LOGIN     (-2000000302)
 1155 #define S_FTP_PORT      (-2000000303)
 1156 #define S_FTP_NO_FILE       (-2000000304)
 1157 #define S_FTP_FILE_ERROR    (-2000000305)
 1158 
 1159 #define S_SSL_ERROR     (-2000000400)
 1160 #define S_NO_SSL        (-2000000401)
 1161 
 1162 #define S_NO_SMB_CLIENT     (-2000000500)
 1163 
 1164 #define S_WAIT_REDIR        (-2000000600)
 1165 
 1166 #define S_UNKNOWN_ERROR     (-2000000700)
 1167 
 1168 #define S_MAX           (-2000000900)
 1169 
 1170 extern struct s_msg_dsc {
 1171     int n;
 1172     unsigned char *msg;
 1173 } msg_dsc[];
 1174 
 1175 struct status {
 1176     struct status *next;
 1177     struct status *prev;
 1178     struct connection *c;
 1179     struct cache_entry *ce;
 1180     int state;
 1181     int prev_error;
 1182     int pri;
 1183     void (*end)(struct status *, void *);
 1184     void *data;
 1185     struct remaining_info *prg;
 1186 };
 1187 
 1188 void check_queue(void *dummy);
 1189 unsigned long connect_info(int);
 1190 void send_connection_info(struct connection *c);
 1191 void setcstate(struct connection *c, int);
 1192 int get_keepalive_socket(struct connection *c, int *protocol_data);
 1193 void add_keepalive_socket(struct connection *c, ttime timeout, int protocol_data);
 1194 void run_connection(struct connection *c);
 1195 int is_connection_restartable(struct connection *c);
 1196 void retry_connection(struct connection *c);
 1197 void abort_connection(struct connection *c);
 1198 void end_connection(struct connection *c);
 1199 int load_url(unsigned char *, struct status *, int, int);
 1200 void change_connection(struct status *, struct status *, int);
 1201 void detach_connection(struct status *, off_t);
 1202 void abort_all_connections();
 1203 void abort_background_connections();
 1204 void abort_all_keepalive_connections();
 1205 int is_entry_used(struct cache_entry *);
 1206 void connection_timeout(struct connection *);
 1207 void set_timeout(struct connection *);
 1208 void add_blacklist_entry(unsigned char *, int);
 1209 void del_blacklist_entry(unsigned char *, int);
 1210 int get_blacklist_flags(unsigned char *);
 1211 void free_blacklist();
 1212 
 1213 #define BL_HTTP10       1
 1214 #define BL_NO_ACCEPT_LANGUAGE   2
 1215 #define BL_NO_CHARSET       4
 1216 #define BL_NO_RANGE     8
 1217 
 1218 /* url.c */
 1219 
 1220 struct session;
 1221 
 1222 #define POST_CHAR       1
 1223 #define POST_CHAR_STRING    "\001"
 1224 
 1225 static inline int end_of_dir(unsigned char c)
 1226 {
 1227     return c == POST_CHAR || c == '#' || c == ';' || c == '?';
 1228 }
 1229 
 1230 int parse_url(unsigned char *, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **, int *, unsigned char **);
 1231 unsigned char *get_host_name(unsigned char *);
 1232 unsigned char *get_host_and_pass(unsigned char *);
 1233 unsigned char *get_user_name(unsigned char *);
 1234 unsigned char *get_pass(unsigned char *);
 1235 unsigned char *get_port_str(unsigned char *);
 1236 int get_port(unsigned char *);
 1237 void (*get_protocol_handle(unsigned char *))(struct connection *);
 1238 void (*get_external_protocol_function(unsigned char *))(struct session *, unsigned char *);
 1239 unsigned char *get_url_data(unsigned char *);
 1240 unsigned char *join_urls(unsigned char *, unsigned char *);
 1241 unsigned char *translate_url(unsigned char *, unsigned char *);
 1242 unsigned char *extract_position(unsigned char *);
 1243 void get_filename_from_url(unsigned char *, unsigned char **, int *);
 1244 int url_not_saveable(unsigned char *);
 1245 void add_conv_str(unsigned char **s, int *l, unsigned char *b, int ll, int encode_special);
 1246 
 1247 /* connect.c */
 1248 
 1249 struct read_buffer {
 1250     int sock;
 1251     int len;
 1252     int close;
 1253     void (*done)(struct connection *, struct read_buffer *);
 1254     unsigned char data[1];
 1255 };
 1256 
 1257 void exception(struct connection *);
 1258 void close_socket(int *);
 1259 void make_connection(struct connection *, int, int *, void (*)(struct connection *));
 1260 int get_pasv_socket(struct connection *, int, int *, unsigned char *);
 1261 void write_to_socket(struct connection *, int, unsigned char *, int, void (*)(struct connection *));
 1262 struct read_buffer *alloc_read_buffer(struct connection *c);
 1263 void read_from_socket(struct connection *, int, struct read_buffer *, void (*)(struct connection *, struct read_buffer *));
 1264 void kill_buffer_data(struct read_buffer *, int);
 1265 
 1266 /* cookies.c */
 1267 
 1268 int set_cookie(struct terminal *, unsigned char *, unsigned char *);
 1269 void send_cookies(unsigned char **, int *, unsigned char *);
 1270 void init_cookies();
 1271 void cleanup_cookies();
 1272 
 1273 /* http.c */
 1274 
 1275 unsigned char *parse_http_header(unsigned char *, unsigned char *, unsigned char **);
 1276 unsigned char *parse_header_param(unsigned char *, unsigned char *);
 1277 int get_http_code(unsigned char *head, int *code, int *version);
 1278 void http_func(struct connection *);
 1279 void proxy_func(struct connection *);
 1280 
 1281 
 1282 /* https.c */
 1283 
 1284 void https_func(struct connection *c);
 1285 #ifdef HAVE_SSL
 1286 void ssl_finish(void);
 1287 SSL *getSSL(void);
 1288 #endif
 1289 
 1290 /* file.c */
 1291 
 1292 void file_func(struct connection *);
 1293 
 1294 /* finger.c */
 1295 
 1296 void finger_func(struct connection *);
 1297 
 1298 /* ftp.c */
 1299 
 1300 #if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
 1301 #define HAVE_IPTOS
 1302 #endif
 1303 
 1304 void ftp_func(struct connection *);
 1305 
 1306 /* smb.c */
 1307 
 1308 void smb_func(struct connection *);
 1309 
 1310 /* mailto.c */
 1311 
 1312 void mailto_func(struct session *, unsigned char *);
 1313 void telnet_func(struct session *, unsigned char *);
 1314 void tn3270_func(struct session *, unsigned char *);
 1315 void mms_func(struct session *, unsigned char *);
 1316 
 1317 /* kbd.c */
 1318 
 1319 #define BM_BUTT     3
 1320 #define B_LEFT      0
 1321 #define B_MIDDLE    1
 1322 #define B_RIGHT     2
 1323 #define BM_ACT      12
 1324 #define B_DOWN      0
 1325 #define B_UP        4
 1326 #define B_DRAG      8
 1327 
 1328 #define KBD_ENTER   0x100
 1329 #define KBD_BS      0x101
 1330 #define KBD_TAB     0x102
 1331 #define KBD_ESC     0x103
 1332 #define KBD_LEFT    0x104
 1333 #define KBD_RIGHT   0x105
 1334 #define KBD_UP      0x106
 1335 #define KBD_DOWN    0x107
 1336 #define KBD_INS     0x108
 1337 #define KBD_DEL     0x109
 1338 #define KBD_HOME    0x10a
 1339 #define KBD_END     0x10b
 1340 #define KBD_PAGE_UP 0x10c
 1341 #define KBD_PAGE_DOWN   0x10d
 1342 
 1343 #define KBD_F1      0x120
 1344 #define KBD_F2      0x121
 1345 #define KBD_F3      0x122
 1346 #define KBD_F4      0x123
 1347 #define KBD_F5      0x124
 1348 #define KBD_F6      0x125
 1349 #define KBD_F7      0x126
 1350 #define KBD_F8      0x127
 1351 #define KBD_F9      0x128
 1352 #define KBD_F10     0x129
 1353 #define KBD_F11     0x12a
 1354 #define KBD_F12     0x12b
 1355 
 1356 #define KBD_CTRL_C  0x200
 1357 
 1358 #define KBD_SHIFT   1
 1359 #define KBD_CTRL    2
 1360 #define KBD_ALT     4
 1361 
 1362 void handle_trm(int, int, int, int, int, void *, int);
 1363 void free_all_itrms();
 1364 void resize_terminal();
 1365 void dispatch_special(unsigned char *);
 1366 void kbd_ctrl_c();
 1367 int is_blocked();
 1368 
 1369 extern unsigned char init_seq[];
 1370 extern unsigned char init_seq_x_mouse[];
 1371 extern unsigned char init_seq_tw_mouse[];
 1372 extern unsigned char term_seq[];
 1373 extern unsigned char term_seq_x_mouse[];
 1374 extern unsigned char term_seq_tw_mouse[];
 1375 
 1376 /* terminal.c */
 1377 
 1378 typedef unsigned short chr;
 1379 
 1380 struct event {
 1381     int ev;
 1382     int x;
 1383     int y;
 1384     my_intptr_t b;
 1385 };
 1386 
 1387 #define EV_INIT     0
 1388 #define EV_KBD      1
 1389 #define EV_MOUSE    2
 1390 #define EV_REDRAW   3
 1391 #define EV_RESIZE   4
 1392 #define EV_ABORT    5
 1393 
 1394 struct window {
 1395     struct window *next;
 1396     struct window *prev;
 1397     void (*handler)(struct window *, struct event *, int fwd);
 1398     void *data;
 1399     int xp, yp;
 1400     struct terminal *term;
 1401 };
 1402 
 1403 #define MAX_TERM_LEN    32  /* this must be multiple of 8! (alignment problems) */
 1404 
 1405 #define MAX_CWD_LEN 4096    /* this must be multiple of 8! (alignment problems) */  
 1406 
 1407 #define ENV_XWIN    1
 1408 #define ENV_SCREEN  2
 1409 #define ENV_OS2VIO  4
 1410 #define ENV_BE      8
 1411 #define ENV_TWIN    16
 1412 #define ENV_WIN32   32
 1413 #define ENV_INTERIX 64
 1414 
 1415 struct terminal {
 1416     struct terminal *next;
 1417     struct terminal *prev;
 1418     int master;
 1419     int fdin;
 1420     int fdout;
 1421     int x;
 1422     int y;
 1423     int environment;
 1424     unsigned char term[MAX_TERM_LEN];
 1425     unsigned char cwd[MAX_CWD_LEN];
 1426     unsigned *screen;
 1427     unsigned *last_screen;
 1428     struct term_spec *spec;
 1429     int cx;
 1430     int cy;
 1431     int lcx;
 1432     int lcy;
 1433     int dirty;
 1434     int redrawing;
 1435     int blocked;
 1436     unsigned char *input_queue;
 1437     int qlen;
 1438     struct list_head windows;
 1439     unsigned char *title;
 1440 };
 1441 
 1442 struct term_spec {
 1443     struct term_spec *next;
 1444     struct term_spec *prev;
 1445     unsigned char term[MAX_TERM_LEN];
 1446     int mode;
 1447     int m11_hack;
 1448     int restrict_852;
 1449     int block_cursor;
 1450     int col;
 1451     int charset;
 1452 };
 1453 
 1454 #define TERM_DUMB   0
 1455 #define TERM_VT100  1
 1456 #define TERM_LINUX  2
 1457 #define TERM_KOI8   3
 1458 #define TERM_FREEBSD    4
 1459 
 1460 #define ATTR_FRAME  0x8000
 1461 
 1462 extern struct list_head term_specs;
 1463 extern struct list_head terminals;
 1464 
 1465 int hard_write(int, unsigned char *, int);
 1466 int hard_read(int, unsigned char *, int);
 1467 unsigned char *get_cwd();
 1468 void set_cwd(unsigned char *);
 1469 struct terminal *init_term(int, int, void (*)(struct window *, struct event *, int));
 1470 void sync_term_specs();
 1471 struct term_spec *new_term_spec(unsigned char *);
 1472 void free_term_specs();
 1473 void destroy_terminal(struct terminal *);
 1474 void redraw_terminal(struct terminal *);
 1475 void redraw_terminal_all(struct terminal *);
 1476 void redraw_terminal_cls(struct terminal *);
 1477 void cls_redraw_all_terminals();
 1478 void redraw_from_window(struct window *);
 1479 void redraw_below_window(struct window *);
 1480 void add_window(struct terminal *, void (*)(struct window *, struct event *, int), void *);
 1481 void add_window_at_pos(struct terminal *, void (*)(struct window *, struct event *, int), void *, struct window *);
 1482 void delete_window(struct window *);
 1483 void delete_window_ev(struct window *, struct event *ev);
 1484 void set_window_ptr(struct window *, int, int);
 1485 void get_parent_ptr(struct window *, int *, int *);
 1486 struct window *get_root_window(struct terminal *);
 1487 void add_empty_window(struct terminal *, void (*)(void *), void *);
 1488 void redraw_screen(struct terminal *);
 1489 void redraw_all_terminals();
 1490 void set_char(struct terminal *, int, int, unsigned);
 1491 unsigned get_char(struct terminal *, int, int);
 1492 void set_color(struct terminal *, int, int, unsigned);
 1493 void set_only_char(struct terminal *, int, int, unsigned);
 1494 void set_line(struct terminal *, int, int, int, chr *);
 1495 void set_line_color(struct terminal *, int, int, int, unsigned);
 1496 void fill_area(struct terminal *, int, int, int, int, unsigned);
 1497 void draw_frame(struct terminal *, int, int, int, int, unsigned, int);
 1498 void print_text(struct terminal *, int, int, int, unsigned char *, unsigned);
 1499 void set_cursor(struct terminal *, int, int, int, int);
 1500 void destroy_all_terminals();
 1501 void block_itrm(int);
 1502 int unblock_itrm(int);
 1503 void exec_thread(unsigned char *, int);
 1504 void close_handle(void *);
 1505 
 1506 #define TERM_FN_TITLE   1
 1507 #define TERM_FN_RESIZE  2
 1508 
 1509 void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, int);
 1510 void set_terminal_title(struct terminal *, unsigned char *);
 1511 void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
 1512 
 1513 /* language.c */
 1514 
 1515 #include "language.h"
 1516 
 1517 extern unsigned char dummyarray[];
 1518 
 1519 extern int current_language;
 1520 
 1521 void init_trans();
 1522 void shutdown_trans();
 1523 unsigned char *get_text_translation(unsigned char *, struct terminal *term);
 1524 unsigned char *get_english_translation(unsigned char *);
 1525 void set_language(int);
 1526 int n_languages();
 1527 unsigned char *language_name(int);
 1528 
 1529 #define _(x_, y_) get_text_translation(x_, y_)
 1530 #define TEXT_(x) (dummyarray + x) /* TEXT causes name clash on windows */
 1531 
 1532 /* af_unix.c */
 1533 
 1534 int bind_to_af_unix();
 1535 void af_unix_close();
 1536 
 1537 /* main.c */
 1538 
 1539 extern int retval;
 1540 
 1541 extern unsigned char *path_to_exe;
 1542 extern unsigned char **g_argv;
 1543 extern int g_argc;
 1544 
 1545 void unhandle_terminal_signals(struct terminal *term);
 1546 int attach_terminal(int, int, int, void *, int);
 1547 void program_exit();
 1548 void shrink_memory(int);
 1549 
 1550 /* types.c */
 1551 
 1552 struct assoc {
 1553     struct assoc *next;
 1554     struct assoc *prev;
 1555     unsigned cnt;
 1556     unsigned char *label;
 1557     unsigned char *ct;
 1558     unsigned char *prog;
 1559     int cons;
 1560     int xwin;
 1561     int block;
 1562     int ask;
 1563     int system;
 1564 };
 1565 
 1566 struct extension {
 1567     struct extension *next;
 1568     struct extension *prev;
 1569     unsigned cnt;
 1570     unsigned char *ext;
 1571     unsigned char *ct;
 1572 };
 1573 
 1574 struct protocol_program {
 1575     struct protocol_program *next;
 1576     struct protocol_program *prev;
 1577     unsigned char *prog;
 1578     int system;
 1579 };
 1580 
 1581 extern struct list_head assoc;
 1582 extern struct list_head extensions;
 1583 
 1584 extern struct list_head mailto_prog;
 1585 extern struct list_head telnet_prog;
 1586 extern struct list_head tn3270_prog;
 1587 extern struct list_head mms_prog;
 1588 
 1589 unsigned char *get_content_type(unsigned char *, unsigned char *);
 1590 struct assoc *get_type_assoc(struct terminal *term, unsigned char *);
 1591 void update_assoc(struct assoc *);
 1592 void update_ext(struct extension *);
 1593 void update_prog(struct list_head *, unsigned char *, int);
 1594 unsigned char *get_prog(struct list_head *);
 1595 void free_types();
 1596 
 1597 void menu_add_ct(struct terminal *, void *, void *);
 1598 void menu_del_ct(struct terminal *, void *, void *);
 1599 void menu_list_assoc(struct terminal *, void *, void *);
 1600 void menu_add_ext(struct terminal *, void *, void *);
 1601 void menu_del_ext(struct terminal *, void *, void *);
 1602 void menu_list_ext(struct terminal *, void *, void *);
 1603 
 1604 int is_html_type(unsigned char *ct);
 1605 
 1606 /* session.c */
 1607 
 1608 struct link_def {
 1609     unsigned char *link;
 1610     unsigned char *target;
 1611 };
 1612 
 1613 struct line {
 1614     int l;
 1615     chr c;
 1616     chr *d;
 1617 };
 1618 
 1619 struct point {
 1620     int x;
 1621     int y;
 1622 };
 1623 
 1624 struct form {
 1625     unsigned char *action;
 1626     unsigned char *target;
 1627     int method;
 1628     int num;
 1629 };
 1630 
 1631 #define FM_GET      0
 1632 #define FM_POST     1
 1633 #define FM_POST_MP  2
 1634 
 1635 #define FC_TEXT     1
 1636 #define FC_PASSWORD 2
 1637 #define FC_FILE     3
 1638 #define FC_TEXTAREA 4
 1639 #define FC_CHECKBOX 5
 1640 #define FC_RADIO    6
 1641 #define FC_SELECT   7
 1642 #define FC_SUBMIT   8
 1643 #define FC_IMAGE    9
 1644 #define FC_RESET    10
 1645 #define FC_HIDDEN   11
 1646 
 1647 struct form_control {
 1648     struct form_control *next;
 1649     struct form_control *prev;
 1650     int form_num;
 1651     int ctrl_num;
 1652     int g_ctrl_num;
 1653     int position;
 1654     int method;
 1655     unsigned char *action;
 1656     unsigned char *target;
 1657     int type;
 1658     unsigned char *name;
 1659     unsigned char *alt;
 1660     int ro;
 1661     unsigned char *default_value;
 1662     int default_state;
 1663     int size;
 1664     int cols, rows, wrap;
 1665     int maxlength;
 1666     int nvalues;
 1667     unsigned char **values;
 1668     unsigned char **labels;
 1669     struct menu_item *menu;
 1670 };
 1671 
 1672 struct form_state {
 1673     int form_num;
 1674     int ctrl_num;
 1675     int g_ctrl_num;
 1676     int position;
 1677     int type;
 1678     unsigned char *value;
 1679     int state;
 1680     int vpos;
 1681     int vypos;
 1682 };
 1683 
 1684 struct link {
 1685     int type;
 1686     int num;
 1687     unsigned char *where;
 1688     unsigned char *target;
 1689     unsigned char *where_img;
 1690     struct form_control *form;
 1691     unsigned sel_color;
 1692     int n;
 1693     struct point *pos;
 1694 };
 1695 
 1696 #define L_LINK      0
 1697 #define L_BUTTON    1
 1698 #define L_CHECKBOX  2
 1699 #define L_SELECT    3
 1700 #define L_FIELD     4
 1701 #define L_AREA      5
 1702 
 1703 #define SIZEOF_F_DATA sizeof(struct f_data)
 1704 
 1705 struct link_bg {
 1706     int x, y;
 1707     unsigned c;
 1708 };
 1709 
 1710 struct tag {
 1711     struct tag *next;
 1712     struct tag *prev;
 1713     int x;
 1714     int y;
 1715     unsigned char name[1];
 1716 };
 1717 
 1718 struct rgb {
 1719     unsigned char r, g, b;
 1720     unsigned char pad;
 1721 };
 1722 
 1723 struct document_setup {
 1724     int assume_cp, hard_assume;
 1725     int tables, frames, images;
 1726     int margin;
 1727     int num_links, table_order;
 1728 };
 1729 
 1730 struct document_options {
 1731     int xw, yw; /* size of window */
 1732     int xp, yp; /* pos of window */
 1733     int col, cp, assume_cp, hard_assume;
 1734     int tables, frames, images, margin; /* if you add anything, fix it in compare_opt */
 1735     int plain;
 1736     int num_links, table_order;
 1737     struct rgb default_fg;
 1738     struct rgb default_bg;
 1739     struct rgb default_link;
 1740     struct rgb default_vlink;
 1741     unsigned char *framename;
 1742     int real_cp;    /* codepage of document. Does not really belong here. Must not be compared. Used only in get_attr_val */
 1743 };
 1744 
 1745 static inline void ds2do(struct document_setup *ds, struct document_options *doo)
 1746 {
 1747     doo->assume_cp = ds->assume_cp;
 1748     doo->hard_assume = ds->hard_assume;
 1749     doo->tables = ds->tables;
 1750     doo->frames = ds->frames;
 1751     doo->images = ds->images;
 1752     doo->margin = ds->margin;
 1753     doo->num_links = ds->num_links;
 1754     doo->table_order = ds->table_order;
 1755 }
 1756 
 1757 struct node {
 1758     struct node *next;
 1759     struct node *prev;
 1760     int x, y;
 1761     int xw, yw;
 1762 };
 1763 
 1764 struct search {
 1765     unsigned char c;
 1766     int n:24;   /* This structure is size-critical */
 1767     int x, y;
 1768 };
 1769 
 1770 struct frameset_desc;
 1771 
 1772 struct frame_desc {
 1773     struct frameset_desc *subframe;
 1774     unsigned char *name;
 1775     unsigned char *url;
 1776     int line;
 1777     int xw, yw;
 1778 };
 1779 
 1780 struct frameset_desc {
 1781     int n;
 1782     int x, y;
 1783     int xp, yp;
 1784     struct frame_desc f[1];
 1785 };
 1786 
 1787 struct f_data {
 1788     struct f_data *next;
 1789     struct f_data *prev;
 1790     int refcount;
 1791     unsigned char *url;
 1792     struct document_options opt;
 1793     unsigned char *title;
 1794     int cp, ass;
 1795     int x, y; /* size of document */
 1796     ttime time_to_get;
 1797     tcount use_tag;
 1798     int frame;
 1799     struct frameset_desc *frame_desc;
 1800     int bg;
 1801     struct line *data;
 1802     struct link *links;
 1803     int nlinks;
 1804     struct link **lines1;
 1805     struct link **lines2;
 1806     struct list_head forms;
 1807     struct list_head tags;
 1808     struct list_head nodes;
 1809     struct search *search;
 1810     int nsearch;
 1811     struct search **slines1;
 1812     struct search **slines2;
 1813 };
 1814 
 1815 struct f_data_c {
 1816     struct f_data_c *next;
 1817     struct f_data_c *prev;
 1818     int used;
 1819     unsigned char *name;
 1820     struct f_data *f_data;
 1821     int xw, yw; /* size of window */
 1822     int xp, yp; /* pos of window */
 1823     int xl, yl; /* last pos of window */
 1824     struct link_bg *link_bg;
 1825     int link_bg_n;
 1826     unsigned char **search_word;
 1827     struct view_state *vs;
 1828     int depth;
 1829 };
 1830 
 1831 struct view_state {
 1832     int view_pos;
 1833     int view_posx;
 1834     int orig_view_pos;
 1835     int orig_view_posx;
 1836     int current_link;
 1837     int orig_link;
 1838     int plain;
 1839     unsigned char *goto_position;
 1840     unsigned char *goto_position_end;
 1841     struct form_state *form_info;
 1842     int form_info_len;
 1843     unsigned char url[1];
 1844 };
 1845 
 1846 struct frame {
 1847     struct frame *next;
 1848     struct frame *prev;
 1849     unsigned char *name;
 1850     int redirect_cnt;
 1851     struct view_state vs;
 1852 };
 1853 
 1854 struct location {
 1855     struct location *next;
 1856     struct location *prev;
 1857     struct list_head frames;
 1858     struct status stat;
 1859     struct view_state vs;
 1860 };
 1861 
 1862 #define WTD_NO      0
 1863 #define WTD_FORWARD 1
 1864 #define WTD_IMGMAP  2
 1865 #define WTD_RELOAD  3
 1866 #define WTD_BACK    4
 1867 
 1868 #define cur_loc(x) ((struct location *)((x)->history.next))
 1869 
 1870 struct kbdprefix {
 1871     int rep;
 1872     int rep_num;
 1873     int prefix;
 1874 };
 1875 
 1876 struct download {
 1877     struct download *next;
 1878     struct download *prev;
 1879     unsigned char *url;
 1880     struct status stat;
 1881     unsigned char *file;
 1882     off_t last_pos;
 1883     int handle;
 1884     int redirect_cnt;
 1885     unsigned char *prog;
 1886     int prog_flags;
 1887     time_t remotetime;
 1888     struct session *ses;
 1889     struct window *win;
 1890     struct window *ask;
 1891 };
 1892 
 1893 extern struct list_head downloads;
 1894 
 1895 struct file_to_load {
 1896     struct file_to_load *next;
 1897     struct file_to_load *prev;
 1898     struct session *ses;
 1899     int req_sent;
 1900     int pri;
 1901     struct cache_entry *ce;
 1902     unsigned char *url;
 1903     struct status stat;
 1904 };
 1905 
 1906 struct session {
 1907     struct session *next;
 1908     struct session *prev;
 1909     struct list_head history;
 1910     struct terminal *term;
 1911     struct window *win;
 1912     int id;
 1913     struct f_data_c *screen;
 1914     struct list_head scrn_frames;
 1915     struct status loading;
 1916     int wtd;
 1917     unsigned char *wtd_target;
 1918     unsigned char *loading_url;
 1919     int display_timer;
 1920     struct list_head more_files;
 1921     unsigned char *goto_position;
 1922     unsigned char *imgmap_href_base;
 1923     unsigned char *imgmap_target_base;
 1924     struct document_setup ds;
 1925     struct kbdprefix kbdprefix;
 1926     int reloadlevel;
 1927     int redirect_cnt;
 1928     struct status tq;
 1929     unsigned char *tq_url;
 1930     struct cache_entry *tq_ce;
 1931     unsigned char *tq_goto_position;
 1932     unsigned char *tq_prog;
 1933     int tq_prog_flags;
 1934     unsigned char *dn_url;
 1935     unsigned char *search_word;
 1936     unsigned char *last_search_word;
 1937     int search_direction;
 1938     int exit_query;
 1939 };
 1940 
 1941 extern struct list_head sessions;
 1942 
 1943 time_t parse_http_date(const char *);
 1944 unsigned char *encode_url(unsigned char *);
 1945 unsigned char *decode_url(unsigned char *);
 1946 unsigned char *subst_file(unsigned char *, unsigned char *, int);
 1947 int are_there_downloads();
 1948 void free_strerror_buf();
 1949 int get_error_from_errno(int errn);
 1950 unsigned char *get_err_msg(int);
 1951 void print_screen_status(struct session *);
 1952 void print_error_dialog(struct session *, struct status *, unsigned char *);
 1953 void start_download(struct session *, unsigned char *);
 1954 void display_download(struct terminal *, struct download *, struct session *);
 1955 int create_download_file(struct terminal *, unsigned char *, int);
 1956 struct file_to_load *request_additional_file(struct session *, unsigned char *, int);
 1957 struct file_to_load *request_additional_loading_file(struct session *, unsigned char *, struct status *, int);
 1958 void process_file_requests(struct session *);
 1959 int read_session_info(int, struct session *, void *, int);
 1960 void *create_session_info(int, unsigned char *, int *);
 1961 void win_func(struct window *, struct event *, int);
 1962 void goto_url_f(struct session *, unsigned char *, unsigned char *);
 1963 void goto_url(struct session *, unsigned char *);
 1964 void abort_loading(struct session *);
 1965 void goto_imgmap(struct session *, unsigned char *, unsigned char *, unsigned char *);
 1966 void go_back(struct session *);
 1967 void reload(struct session*, int);
 1968 struct frame *ses_find_frame(struct session *, unsigned char *);
 1969 struct frame *ses_change_frame_url(struct session *, unsigned char *, unsigned char *);
 1970 void map_selected(struct terminal *, struct link_def *, struct session *);
 1971 void load_frames(struct session *, struct f_data_c *);
 1972 void destroy_session(struct session *);
 1973 void destroy_all_sessions();
 1974 void abort_all_downloads();
 1975 void destroy_location(struct location *);
 1976 
 1977 /* Information about the current document */
 1978 unsigned char *get_current_url(struct session *, unsigned char *, size_t);
 1979 unsigned char *get_current_title(struct session *, unsigned char *, size_t);
 1980 
 1981 unsigned char *get_current_link_url(struct session *, unsigned char *, size_t);
 1982 
 1983 /* bfu.c */
 1984 
 1985 struct memory_list {
 1986     int n;
 1987     void *p[1];
 1988 };
 1989 
 1990 struct memory_list *getml(void *, ...);
 1991 void add_to_ml(struct memory_list **, ...);
 1992 void freeml(struct memory_list *);
 1993 
 1994 #define MENU_FUNC (void (*)(struct terminal *, void *, void *))
 1995 
 1996 extern unsigned char m_bar;
 1997 
 1998 #define M_BAR   (&m_bar)
 1999 
 2000 struct menu_item {
 2001     unsigned char *text;
 2002     unsigned char *rtext;
 2003     unsigned char *hotkey;
 2004     void (*func)(struct terminal *, void *, void *);
 2005     void *data;
 2006     int in_m;
 2007     int free_i;
 2008 };
 2009 
 2010 struct menu {
 2011     int selected;
 2012     int view;
 2013     int xp, yp;
 2014     int x, y, xw, yw;
 2015     int ni;
 2016     void *data;
 2017     struct window *win;
 2018     struct menu_item *items;
 2019     void (*free_function)(void *);
 2020     void *free_data;
 2021     unsigned char hotkeys[1];
 2022 };
 2023 
 2024 struct mainmenu {
 2025     int selected;
 2026     int sp;
 2027     int ni;
 2028     void *data;
 2029     struct window *win;
 2030     struct menu_item *items;
 2031     unsigned char hotkeys[1];
 2032 };
 2033 
 2034 struct history_item {
 2035     struct history_item *next;
 2036     struct history_item *prev;
 2037     unsigned char d[1];
 2038 };
 2039 
 2040 struct history {
 2041     int n;
 2042     struct list_head items;
 2043 };
 2044 
 2045 #define D_END       0
 2046 #define D_CHECKBOX  1
 2047 #define D_FIELD     2
 2048 #define D_FIELD_PASS    3
 2049 #define D_BUTTON    4
 2050 #define D_BOX       5
 2051 
 2052 #define B_ENTER     1
 2053 #define B_ESC       2
 2054 
 2055 struct dialog_item_data;
 2056 struct dialog_data;
 2057 
 2058 struct dialog_item {
 2059     int type;
 2060     int gid, gnum; /* for buttons: gid - flags B_XXX */ /* for fields: min/max */ /* for box: gid is box height */
 2061     int (*fn)(struct dialog_data *, struct dialog_item_data *);
 2062     struct history *history;
 2063     int dlen;
 2064     unsigned char *data;
 2065     void *udata; /* for box: holds list */
 2066     unsigned char *text;
 2067 };
 2068 
 2069 struct dialog_item_data {
 2070     int x, y, l;
 2071     int vpos, cpos;
 2072     int checked;
 2073     struct dialog_item *item;
 2074     struct list_head history;
 2075     struct history_item *cur_hist;
 2076     unsigned char *cdata;
 2077 };
 2078 
 2079 #define EVENT_PROCESSED     0
 2080 #define EVENT_NOT_PROCESSED 1
 2081 
 2082 struct dialog {
 2083     unsigned char *title;
 2084     void (*fn)(struct dialog_data *);
 2085     int (*handle_event)(struct dialog_data *, struct event *);
 2086     void (*abort)(struct dialog_data *);
 2087     void *udata;
 2088     void *udata2;
 2089     int align;
 2090     void (*refresh)(void *);
 2091     void *refresh_data;
 2092     struct dialog_item items[1];
 2093 };
 2094 
 2095 struct dialog_data {
 2096     struct window *win;
 2097     struct dialog *dlg;
 2098     int x, y, xw, yw;
 2099     int n;
 2100     int selected;
 2101     struct memory_list *ml;
 2102     struct dialog_item_data items[1];
 2103 };
 2104 
 2105 struct menu_item *new_menu(int);
 2106 void add_to_menu(struct menu_item **, unsigned char *, unsigned char *, unsigned char *, void (*)(struct terminal *, void *, void *), void *, int);
 2107 void do_menu(struct terminal *, struct menu_item *, void *);
 2108 void do_menu_selected(struct terminal *, struct menu_item *, void *, int, void (*)(void *), void *);
 2109 void do_mainmenu(struct terminal *, struct menu_item *, void *, int);
 2110 void do_dialog(struct terminal *, struct dialog *, struct memory_list *);
 2111 int check_number(struct dialog_data *, struct dialog_item_data *);
 2112 int check_nonempty(struct dialog_data *, struct dialog_item_data *);
 2113 void max_text_width(struct terminal *, unsigned char *, int *);
 2114 void min_text_width(struct terminal *, unsigned char *, int *);
 2115 void dlg_format_text(struct terminal *, struct terminal *, unsigned char *, int, int *, int, int *, int, int);
 2116 void max_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
 2117 void min_buttons_width(struct terminal *, struct dialog_item_data *, int, int *);
 2118 void dlg_format_buttons(struct terminal *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, int);
 2119 void checkboxes_width(struct terminal *, unsigned char **, int *, void (*)(struct terminal *, unsigned char *, int *));
 2120 void dlg_format_checkbox(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, unsigned char *);
 2121 void dlg_format_checkboxes(struct terminal *, struct terminal *, struct dialog_item_data *, int, int, int *, int, int *, unsigned char **);
 2122 void dlg_format_field(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
 2123 void max_group_width(struct terminal *, unsigned char **, struct dialog_item_data *, int, int *);
 2124 void min_group_width(struct terminal *, unsigned char **, struct dialog_item_data *, int, int *);
 2125 void dlg_format_group(struct terminal *, struct terminal *, unsigned char **, struct dialog_item_data *, int, int, int *, int, int *);
 2126 void dlg_format_box(struct terminal *, struct terminal *, struct dialog_item_data *, int, int *, int, int *, int);
 2127 void checkbox_list_fn(struct dialog_data *);
 2128 void group_fn(struct dialog_data *);
 2129 void center_dlg(struct dialog_data *);
 2130 void draw_dlg(struct dialog_data *);
 2131 void display_dlg_item(struct dialog_data *, struct dialog_item_data *, int);
 2132 int ok_dialog(struct dialog_data *, struct dialog_item_data *);
 2133 int cancel_dialog(struct dialog_data *, struct dialog_item_data *);
 2134 void msg_box(struct terminal *, struct memory_list *, unsigned char *, int, /*unsigned char *, void *, int,*/ ...);
 2135 void input_field_fn(struct dialog_data *);
 2136 void input_field(struct terminal *, struct memory_list *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, void *, struct history *, int, unsigned char *, int, int, int (*)(struct dialog_data *, struct dialog_item_data *), void (*)(void *, unsigned char *), void (*)(void *));
 2137 void add_to_history(struct history *, unsigned char *, int);
 2138 
 2139 void box_sel_move(struct dialog_item_data *, int ); 
 2140 void show_dlg_item_box(struct dialog_data *, struct dialog_item_data *);
 2141 void box_sel_set_visible(struct dialog_item_data *, int ); 
 2142 
 2143 /* menu.c */
 2144 
 2145 extern struct history goto_url_history;
 2146 
 2147 void activate_bfu_technology(struct session *, int);
 2148 void dialog_goto_url(struct session *ses, char *url);
 2149 void dialog_save_url(struct session *ses);
 2150 void free_history_lists();
 2151 void query_file(struct session *, unsigned char *, void (*)(struct session *, unsigned char *), void (*)(struct session *));
 2152 void search_dlg(struct session *, struct f_data_c *, int);
 2153 void search_back_dlg(struct session *, struct f_data_c *, int);
 2154 void exit_prog(struct terminal *, void *, struct session *);
 2155 void do_auth_dialog(struct session *);
 2156 
 2157 /* charsets.c */
 2158 
 2159 #include "codepage.h"
 2160 
 2161 struct conv_table {
 2162     int t;
 2163     union {
 2164         unsigned char *str;
 2165         struct conv_table *tbl;
 2166     } u;
 2167 };
 2168 
 2169 int cp2u(unsigned char ch, int from);
 2170 struct conv_table *get_translation_table(int, int);
 2171 int get_entity_number(unsigned char *st, int l);
 2172 unsigned char *get_entity_string(unsigned char *, int, int);
 2173 unsigned char *convert_string(struct conv_table *, unsigned char *, int);
 2174 int get_cp_index(unsigned char *n);
 2175 unsigned char *get_cp_name(int);
 2176 unsigned char *get_cp_mime_name(int);
 2177 int is_cp_special(int);
 2178 void free_conv_table();
 2179 
 2180 unsigned char charset_upcase(unsigned char, int);
 2181 void charset_upcase_string(unsigned char **, int);
 2182 
 2183 /* view.c */
 2184 
 2185 int can_open_in_new(struct terminal *);
 2186 void open_in_new_window(struct terminal *, void (*)(struct terminal *, void (*)(struct terminal *, unsigned char *, unsigned char *), struct session *ses), struct session *);
 2187 void send_open_in_new_xterm(struct terminal *term, void (*open_window)(struct terminal *term, unsigned char *, unsigned char *), struct session *ses);
 2188 void send_open_new_xterm(struct terminal *, void (*)(struct terminal *, unsigned char *, unsigned char *), struct session *);
 2189 void destroy_fc(struct form_control *);
 2190 void sort_links(struct f_data *);
 2191 void destroy_formatted(struct f_data *);
 2192 void clear_formatted(struct f_data *);
 2193 void init_formatted(struct f_data *);
 2194 void detach_formatted(struct f_data_c *);
 2195 void init_vs(struct view_state *, unsigned char *);
 2196 void destroy_vs(struct view_state *);
 2197 void copy_location(struct location *, struct location *);
 2198 void draw_doc(struct terminal *, struct f_data_c *, int);
 2199 int dump_to_file(struct f_data *, int);
 2200 void draw_formatted(struct session *);
 2201 void send_event(struct session *, struct event *);
 2202 void link_menu(struct terminal *, void *, struct session *);
 2203 void save_as(struct terminal *, void *, struct session *);
 2204 void save_url(struct session *, unsigned char *);
 2205 void menu_save_formatted(struct terminal *, void *, struct session *);
 2206 void selected_item(struct terminal *, void *, struct session *);
 2207 void toggle(struct session *, struct f_data_c *, int);
 2208 void do_for_frame(struct session *, void (*)(struct session *, struct f_data_c *, int), int);
 2209 int get_current_state(struct session *);
 2210 unsigned char *print_current_link(struct session *);
 2211 unsigned char *print_current_title(struct session *);
 2212 void loc_msg(struct terminal *, struct location *, struct f_data_c *);
 2213 void state_msg(struct session *);
 2214 void head_msg(struct session *);
 2215 void search_for(struct session *, unsigned char *);
 2216 void search_for_back(struct session *, unsigned char *);
 2217 void find_next(struct session *, struct f_data_c *, int);
 2218 void find_next_back(struct session *, struct f_data_c *, int);
 2219 void set_frame(struct session *, struct f_data_c *, int);
 2220 struct f_data_c *current_frame(struct session *);
 2221 
 2222 /* html.c */
 2223 
 2224 #define AT_BOLD     1
 2225 #define AT_ITALIC   2
 2226 #define AT_UNDERLINE    4
 2227 #define AT_FIXED    8
 2228 #define AT_GRAPHICS 16
 2229 
 2230 #define AL_LEFT     0
 2231 #define AL_CENTER   1
 2232 #define AL_RIGHT    2
 2233 #define AL_BLOCK    3
 2234 #define AL_NO       4
 2235 
 2236 #define AL_MASK     0x7f
 2237 
 2238 #define AL_EXTD_TEXT    0x80
 2239     /* DIRTY! for backward compatibility with old menu code */
 2240 
 2241 struct text_attrib_beginning {
 2242     int attr;
 2243     struct rgb fg;
 2244     struct rgb bg;
 2245 };
 2246 
 2247 struct text_attrib {
 2248     int attr;
 2249     struct rgb fg;
 2250     struct rgb bg;
 2251     int fontsize;
 2252     unsigned char *link;
 2253     unsigned char *target;
 2254     unsigned char *image;
 2255     struct form_control *form;
 2256     struct rgb clink;
 2257     struct rgb vlink;
 2258     unsigned char *href_base;
 2259     unsigned char *target_base;
 2260     unsigned char *select;
 2261     int select_disabled;
 2262 };
 2263 
 2264 #define P_NUMBER    1
 2265 #define P_alpha     2
 2266 #define P_ALPHA     3
 2267 #define P_roman     4
 2268 #define P_ROMAN     5
 2269 #define P_STAR      1
 2270 #define P_O     2
 2271 #define P_PLUS      3
 2272 #define P_LISTMASK  7
 2273 #define P_COMPACT   8
 2274 
 2275 struct par_attrib {
 2276     int align;
 2277     int leftmargin;
 2278     int rightmargin;
 2279     int width;
 2280     int list_level;
 2281     unsigned list_number;
 2282     int dd_margin;
 2283     int flags;
 2284     struct rgb bgcolor;
 2285 };
 2286 
 2287 struct html_element {
 2288     struct html_element *next;
 2289     struct html_element *prev;
 2290     struct text_attrib attr;
 2291     struct par_attrib parattr;
 2292     int invisible;
 2293     unsigned char *name;
 2294     int namelen;
 2295     unsigned char *options;
 2296     int linebreak;
 2297     int dontkill;
 2298     struct frameset_desc *frameset;
 2299 };
 2300 
 2301 extern int get_attr_val_nl;
 2302 
 2303 extern struct list_head html_stack;
 2304 extern int line_breax;
 2305 
 2306 extern unsigned char *startf;
 2307 extern unsigned char *eofff;
 2308 
 2309 #define format_ (((struct html_element *)html_stack.next)->attr)
 2310 #define par_format (((struct html_element *)html_stack.next)->parattr)
 2311 #define html_top (*(struct html_element *)html_stack.next)
 2312 
 2313 extern void *ff;
 2314 extern int (*put_chars_f)(void *, unsigned char *, int);
 2315 extern void (*line_break_f)(void *);
 2316 extern void *(*special_f)(void *, int, ...);
 2317 
 2318 void ln_break(int, void (*)(void *), void *);
 2319 void put_chrs(unsigned char *, int, int (*)(void *, unsigned char *, int), void *);
 2320 
 2321 extern int table_level;
 2322 extern int empty_format;
 2323 
 2324 extern struct form form;
 2325 extern unsigned char *last_form_tag;
 2326 extern unsigned char *last_form_attr;
 2327 extern unsigned char *last_input_tag;
 2328 
 2329 int parse_element(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **, unsigned char **);
 2330 unsigned char *get_attr_val(unsigned char *, unsigned char *);
 2331 int has_attr(unsigned char *, unsigned char *);
 2332 int get_num(unsigned char *, unsigned char *);
 2333 int get_width(unsigned char *, unsigned char *, int);
 2334 int get_color(unsigned char *, unsigned char *, struct rgb *);
 2335 int get_bgcolor(unsigned char *, struct rgb *);
 2336 void html_stack_dup();
 2337 void kill_html_stack_item(struct html_element *);
 2338 unsigned char *skip_comment(unsigned char *, unsigned char *);
 2339 void parse_html(unsigned char *, unsigned char *, int (*)(void *, unsigned char *, int), void (*)(void *), void *(*)(void *, int, ...), void *, unsigned char *);
 2340 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);
 2341 void scan_http_equiv(unsigned char *, unsigned char *, unsigned char **, int *, unsigned char **);
 2342 
 2343 #define SP_TAG      0
 2344 #define SP_CONTROL  1
 2345 #define SP_TABLE    2
 2346 #define SP_USED     3
 2347 #define SP_FRAMESET 4
 2348 #define SP_FRAME    5
 2349 #define SP_NOWRAP   6
 2350 
 2351 struct frameset_param {
 2352     struct frameset_desc *parent;
 2353     int x, y;
 2354     int *xw, *yw;
 2355 };
 2356 
 2357 struct frame_param {
 2358     struct frameset_desc *parent;
 2359     unsigned char *name;
 2360     unsigned char *url;
 2361 };
 2362 
 2363 void free_menu(struct menu_item *);
 2364 void do_select_submenu(struct terminal *, struct menu_item *, struct session *);
 2365 
 2366 /* html_r.c */
 2367 
 2368 struct part {
 2369     int x, y;
 2370     int xp, yp;
 2371     int xmax;
 2372     int xa;
 2373     int cx, cy;
 2374     struct f_data *data;
 2375     int bgcolor;
 2376     unsigned char *spaces;
 2377     int spl;
 2378     int link_num;
 2379     struct list_head uf;
 2380 };
 2381 
 2382 struct sizes {
 2383     int xmin, xmax, y;
 2384 };
 2385 
 2386 extern struct document_options *d_opt;
 2387 extern int last_link_to_move;
 2388 extern int margin;
 2389 
 2390 void xxpand_line(struct part *, int, int);
 2391 void xxpand_lines(struct part *, int);
 2392 void xset_hchar(struct part *, int, int, unsigned);
 2393 void xset_hchars(struct part *, int, int, int, unsigned);
 2394 void align_line(struct part *, int);
 2395 
 2396 void free_table_cache();
 2397 
 2398 struct conv_table *get_convert_table(unsigned char *, int, int, int *, int *, int);
 2399 extern int format_cache_entries;
 2400 unsigned long formatted_info(int);
 2401 void shrink_format_cache(int);
 2402 void count_format_cache();
 2403 void delete_unused_format_cache_entries();
 2404 void format_cache_reactivate(struct f_data *);
 2405 struct part *format_html_part(unsigned char *, unsigned char *, int, int, int, struct f_data *, int, int, unsigned char *, int);
 2406 void cached_format_html(struct view_state *, struct f_data_c *, struct document_options *);
 2407 void html_interpret(struct session *);
 2408 struct link *get_link_at_location(struct f_data *f, int x, int y);
 2409 void get_search_data(struct f_data *);
 2410 
 2411 /* html_tbl.c */
 2412 
 2413 void format_table(unsigned char *, unsigned char *, unsigned char *, unsigned char **, void *);
 2414 
 2415 /* default.c */
 2416 
 2417 #define MAX_STR_LEN 1024
 2418 
 2419 struct option {
 2420     int p;
 2421     unsigned char *(*rd_cmd)(struct option *, unsigned char ***, int *);
 2422     unsigned char *(*rd_cfg)(struct option *, unsigned char *);
 2423     void (*wr_cfg)(struct option *, unsigned char **, int *);
 2424     int min, max;
 2425     void *ptr;
 2426     unsigned char *cfg_name;
 2427     unsigned char *cmd_name;
 2428 };
 2429 
 2430 unsigned char *parse_options(int, unsigned char *[]);
 2431 void init_home();
 2432 unsigned char *read_config_file(unsigned char *name);
 2433 int write_to_config_file(unsigned char *, unsigned char *);
 2434 unsigned char *get_token(unsigned char **line);
 2435 void load_config();
 2436 void write_config(struct terminal *);
 2437 void write_html_config(struct terminal *);
 2438 void end_config();
 2439 
 2440 void load_url_history();
 2441 void save_url_history();
 2442 
 2443 extern int anonymous;
 2444 
 2445 extern unsigned char system_name[];
 2446 extern unsigned char compiler_name[];
 2447 
 2448 extern unsigned char *links_home;
 2449 extern int first_use;
 2450 
 2451 extern int created_home;
 2452 
 2453 extern int no_connect;
 2454 extern int base_session;
 2455 extern int force_html;
 2456 
 2457 #define D_DUMP      1
 2458 #define D_SOURCE    2
 2459 extern int dmp;
 2460 
 2461 extern int async_lookup;
 2462 extern int download_utime;
 2463 extern int max_connections;
 2464 extern int max_connections_to_host;
 2465 extern int max_tries;
 2466 extern int screen_width;
 2467 extern int dump_codepage;
 2468 extern int receive_timeout;
 2469 extern int unrestartable_receive_timeout;
 2470 
 2471 extern struct document_setup dds;
 2472 
 2473 extern int max_format_cache_entries;
 2474 extern int memory_cache_size;
 2475 
 2476 extern struct rgb default_fg;
 2477 extern struct rgb default_bg;
 2478 extern struct rgb default_link;
 2479 extern struct rgb default_vlink;
 2480 
 2481 extern unsigned char http_proxy[];
 2482 extern unsigned char ftp_proxy[];
 2483 extern unsigned char download_dir[];
 2484 
 2485 struct http_bugs {
 2486     int http10;
 2487     int allow_blacklist;
 2488     int bug_302_redirect;
 2489     int bug_post_no_keepalive;
 2490     int no_accept_charset;
 2491 };
 2492 
 2493 extern struct http_bugs http_bugs;
 2494 
 2495 struct ftp_options {
 2496     unsigned char anon_pass[MAX_STR_LEN];
 2497     int fast_ftp;
 2498     int passive_ftp;
 2499     int set_tos;
 2500 };
 2501 
 2502 extern struct ftp_options ftp_options;
 2503 
 2504 /* bookmarks.c */
 2505 
 2506 /* Where all bookmarks are kept */
 2507 extern struct list_head bookmarks;
 2508 
 2509 /* A pointer independent id that bookmarks can be identified by. Guarenteed to 
 2510     be unique between all bookmarks */
 2511 typedef int bookmark_id;
 2512 extern bookmark_id next_bookmark_id;
 2513 #define     BAD_BOOKMARK_ID     (bookmark_id)(-1)
 2514 
 2515 
 2516 /* Stores display information about a box. Kept in cdata. */
 2517 struct dlg_data_item_data_box {
 2518     int sel;    /* Item currently selected */   
 2519     int box_top;    /* Index into items of the item that is on the top line of the box */
 2520     struct list_head items; /* The list being displayed */
 2521     int list_len;   /* Number of items in the list */
 2522 };
 2523 
 2524 /* An item in a box */
 2525 struct box_item {
 2526     struct box_item *next;
 2527     struct box_item *prev;
 2528     unsigned char *text;    /* Text to display */
 2529     void *data; /* data */
 2530 };
 2531 
 2532 
 2533 void show_dlg_item_box(struct dialog_data *, struct dialog_item_data *); 
 2534 
 2535 #define BOX_HILIGHT_FUNC (void (*)(struct terminal *, struct dlg_data_item_data_box *, struct box_item *))
 2536 #define BOX_ON_SELECTED_FUNC (int (*)(struct terminal *, struct dlg_data_item_data_box *, struct box_item *))
 2537 
 2538 /* Ops dealing with box data */
 2539 /* */
 2540 #define get_box_from_dlg_item_data(x) ((struct dlg_data_item_data_box *)(x->cdata))
 2541 #define get_box_list_height(x) (x->data_len)
 2542 
 2543 /* V.05 bookmarks: */
 2544 /*
 2545 struct bookmark {
 2546     struct bookmark *next;
 2547     struct bookmark *prev;
 2548     bookmark_id id; Bookmark id 
 2549     unsigned char *title;    title of bookmark 
 2550     unsigned char *url;  Location of bookmarked item 
 2551 };*/
 2552 
 2553 struct bookmark {
 2554     struct bookmark *next;
 2555     struct bookmark *prev;
 2556     bookmark_id id; /* Bookmark id */
 2557     unsigned char *title;   /* title of bookmark */
 2558     unsigned char *url; /* Location of bookmarked item */
 2559     unsigned int type; /* The type of bookmark we're dealing with. */
 2560     void *type_data; /* Type-dependent data. */
 2561 };
 2562 
 2563 void finalize_bookmarks();
 2564 
 2565 void read_bookmarks();
 2566 void write_bookmarks();
 2567 
 2568 void bookmark_menu(struct terminal *, void *, struct session *);
 2569 
 2570 /* Launches bookmark manager */
 2571 void menu_bookmark_manager(struct terminal *, void *, struct session *);
 2572 
 2573 void add_bookmark(const unsigned char *, const unsigned char *);
 2574 
 2575 struct bookmark *create_bookmark(const unsigned char *, const unsigned char *);
 2576 
 2577 /* Launches add dialogs */
 2578 void launch_bm_add_link_dialog(struct terminal *,struct dialog_data *,struct session *);
 2579 void launch_bm_add_doc_dialog(struct terminal *,struct dialog_data *,struct session *);
 2580 
 2581 /* kbdbind.c */
 2582 
 2583 #define KM_MAIN     0
 2584 #define KM_EDIT     1
 2585 #define KM_MENU     2
 2586 #define KM_MAX      3
 2587 
 2588 enum {
 2589     ACT_ADD_BOOKMARK,
 2590     ACT_AUTO_COMPLETE,
 2591     ACT_BACK,
 2592     ACT_BACKSPACE,
 2593     ACT_BOOKMARK_MANAGER,
 2594     ACT_COPY_CLIPBOARD,
 2595     ACT_CUT_CLIPBOARD,
 2596     ACT_DELETE,
 2597     ACT_DOCUMENT_INFO,
 2598     ACT_DOWN,
 2599     ACT_DOWNLOAD,
 2600     ACT_END,
 2601     ACT_ENTER,
 2602     ACT_FILE_MENU,
 2603     ACT_FIND_NEXT,
 2604     ACT_FIND_NEXT_BACK,
 2605     ACT_GOTO_URL,
 2606     ACT_GOTO_URL_CURRENT,
 2607     ACT_GOTO_URL_CURRENT_LINK,
 2608     ACT_HEADER_INFO,
 2609     ACT_HOME,
 2610     ACT_KILL_TO_BOL,
 2611     ACT_KILL_TO_EOL,
 2612     ACT_LEFT,
 2613     ACT_MENU,
 2614     ACT_NEXT_FRAME,
 2615     ACT_OPEN_NEW_WINDOW,
 2616     ACT_OPEN_LINK_IN_NEW_WINDOW,
 2617     ACT_PAGE_DOWN,
 2618     ACT_PAGE_UP,
 2619     ACT_PASTE_CLIPBOARD,
 2620     ACT_PREVIOUS_FRAME,
 2621     ACT_REALLYQUIT,
 2622     ACT_QUIT,
 2623     ACT_RELOAD,
 2624     ACT_RIGHT,
 2625     ACT_SCROLL_DOWN,
 2626     ACT_SCROLL_LEFT,
 2627     ACT_SCROLL_RIGHT,
 2628     ACT_SCROLL_UP,
 2629     ACT_SEARCH,
 2630     ACT_SEARCH_BACK,
 2631     ACT_TOGGLE_DISPLAY_IMAGES,
 2632     ACT_TOGGLE_DISPLAY_TABLES,
 2633     ACT_TOGGLE_HTML_PLAIN,
 2634     ACT_UP,
 2635     ACT_VIEW_IMAGE,
 2636     ACT_ZOOM_FRAME
 2637 };
 2638 
 2639 void init_keymaps();
 2640 void free_keymaps();
 2641 int kbd_action(int, struct event *);
 2642 unsigned char *bind_rd(struct option *, unsigned char *);
 2643 unsigned char *unbind_rd(struct option *, unsigned char *);