4 #include <stdio.h> /* for FILENAME_MAX */
5 #include <stddef.h> /* for wchar_t */
8 * Global variables. Most modules declare these `extern', but
9 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
10 * module, and so will get them properly defined.
13 #ifdef PUTTY_DO_GLOBALS
22 typedef struct config_tag Config
;
23 typedef struct backend_tag Backend
;
24 typedef struct terminal_tag Terminal
;
30 /* Three attribute types:
31 * The ATTRs (normal attributes) are stored with the characters in the main
34 * The TATTRs (temporary attributes) are generated on the fly, they can overlap
35 * with characters but not with normal attributes.
37 * The LATTRs (line attributes) conflict with no others and only have one
38 * value per line. But on area clears the LATTR cells are set to the erase_char
39 * (or DEFAULT_ATTR + 'E')
41 * ATTR_INVALID is an illegal colour combination.
44 #define TATTR_ACTCURS 0x4UL /* active cursor (block) */
45 #define TATTR_PASCURS 0x2UL /* passive cursor (box) */
46 #define TATTR_RIGHTCURS 0x1UL /* cursor-on-RHS */
48 #define LATTR_NORM 0x00000000UL
49 #define LATTR_WIDE 0x01000000UL
50 #define LATTR_TOP 0x02000000UL
51 #define LATTR_BOT 0x03000000UL
52 #define LATTR_MODE 0x03000000UL
53 #define LATTR_WRAPPED 0x10000000UL
54 #define LATTR_WRAPPED2 0x20000000UL
56 #define ATTR_INVALID 0x00FF0000UL
58 /* Like Linux use the F000 page for direct to font. */
59 #define ATTR_OEMCP 0x0000F000UL /* OEM Codepage DTF */
60 #define ATTR_ACP 0x0000F100UL /* Ansi Codepage DTF */
62 /* These are internal use overlapping with the UTF-16 surrogates */
63 #define ATTR_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
64 #define ATTR_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
65 #define ATTR_SCOACS 0x0000DA00UL /* SCO Alternate charset */
66 #define ATTR_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
67 #define CSET_MASK 0x0000FF00UL /* Character set mask; MUST be 0xFF00 */
69 #define DIRECT_CHAR(c) ((c&0xFC00)==0xD800)
70 #define DIRECT_FONT(c) ((c&0xFE00)==0xF000)
72 #define UCSERR (ATTR_LINEDRW|'a') /* UCS Format error character. */
74 * UCSWIDE is a special value used in the terminal data to signify
75 * the character cell containing the right-hand half of a CJK wide
76 * character. We use 0xDFFF because it's part of the surrogate
77 * range and hence won't be used for anything else (it's impossible
78 * to input it via UTF-8 because our UTF-8 decoder correctly
79 * rejects surrogates).
81 #define UCSWIDE 0xDFFF
83 #define ATTR_NARROW 0x20000000UL
84 #define ATTR_WIDE 0x10000000UL
85 #define ATTR_BOLD 0x01000000UL
86 #define ATTR_UNDER 0x02000000UL
87 #define ATTR_REVERSE 0x04000000UL
88 #define ATTR_BLINK 0x08000000UL
89 #define ATTR_FGMASK 0x000F0000UL
90 #define ATTR_BGMASK 0x00F00000UL
91 #define ATTR_COLOURS 0x00FF0000UL
92 #define ATTR_FGSHIFT 16
93 #define ATTR_BGSHIFT 20
95 #define ATTR_DEFAULT 0x00980000UL
96 #define ATTR_DEFFG 0x00080000UL
97 #define ATTR_DEFBG 0x00900000UL
98 #define ERASE_CHAR (ATTR_DEFAULT | ATTR_ASCII | ' ')
99 #define ATTR_MASK 0xFFFFFF00UL
100 #define CHAR_MASK 0x000000FFUL
102 #define ATTR_CUR_AND (~(ATTR_BOLD|ATTR_REVERSE|ATTR_BLINK|ATTR_COLOURS))
103 #define ATTR_CUR_XOR 0x00BA0000UL
108 char *buffer
; /* so memory can be freed later */
111 struct unicode_data
{
116 wchar_t unitab_scoacs
[256];
117 wchar_t unitab_line
[256];
118 wchar_t unitab_font
[256];
119 wchar_t unitab_xterm
[256];
120 wchar_t unitab_oemcp
[256];
121 unsigned char unitab_ctrl
[256];
124 #define LGXF_OVR 1 /* existing logfile overwrite */
125 #define LGXF_APN 0 /* existing logfile append */
126 #define LGXF_ASK -1 /* existing logfile ask */
127 #define LGTYP_NONE 0 /* logmode: no logging */
128 #define LGTYP_ASCII 1 /* logmode: pure ascii */
129 #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
130 #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
133 TS_AYT
, TS_BRK
, TS_SYNCH
, TS_EC
, TS_EL
, TS_GA
, TS_NOP
, TS_ABORT
,
134 TS_AO
, TS_IP
, TS_SUSP
, TS_EOR
, TS_EOF
, TS_LECHO
, TS_RECHO
, TS_PING
,
140 MBT_LEFT
, MBT_MIDDLE
, MBT_RIGHT
, /* `raw' button designations */
141 MBT_SELECT
, MBT_EXTEND
, MBT_PASTE
, /* `cooked' button designations */
142 MBT_WHEEL_UP
, MBT_WHEEL_DOWN
/* mouse wheel */
146 MA_NOTHING
, MA_CLICK
, MA_2CLK
, MA_3CLK
, MA_DRAG
, MA_RELEASE
150 VT_XWINDOWS
, VT_OEMANSI
, VT_OEMONLY
, VT_POORMAN
, VT_UNICODE
155 * SSH ciphers (both SSH1 and SSH2)
157 CIPHER_WARN
, /* pseudo 'cipher' */
160 CIPHER_AES
, /* (SSH 2 only) */
162 CIPHER_MAX
/* no. ciphers (inc warn) */
167 * Line discipline option states: off, on, up to the backend.
169 LD_YES
, LD_NO
, LD_BACKEND
174 * Line discipline options which the backend might try to control.
176 LD_EDIT
, /* local line editing */
177 LD_ECHO
/* local echo */
182 * Close On Exit behaviours. (cfg.close_on_exit)
184 COE_NEVER
, /* Never close the window */
185 COE_NORMAL
, /* Close window on "normal" (non-error) exits only */
186 COE_ALWAYS
/* Always close the window */
190 char *(*init
) (void *frontend_handle
, void **backend_handle
, Config
*cfg
,
191 char *host
, int port
, char **realhost
, int nodelay
);
192 /* back->reconfig() passes in a replacement configuration. */
193 void (*reconfig
) (void *handle
, Config
*cfg
);
194 /* back->send() returns the current amount of buffered data. */
195 int (*send
) (void *handle
, char *buf
, int len
);
196 /* back->sendbuffer() does the same thing but without attempting a send */
197 int (*sendbuffer
) (void *handle
);
198 void (*size
) (void *handle
, int width
, int height
);
199 void (*special
) (void *handle
, Telnet_Special code
);
200 Socket(*socket
) (void *handle
);
201 int (*exitcode
) (void *handle
);
202 int (*sendok
) (void *handle
);
203 int (*ldisc
) (void *handle
, int);
204 void (*provide_ldisc
) (void *handle
, void *ldisc
);
205 void (*provide_logctx
) (void *handle
, void *logctx
);
207 * back->unthrottle() tells the back end that the front end
208 * buffer is clearing.
210 void (*unthrottle
) (void *handle
, int);
214 extern struct backend_list
{
224 enum { PROT_RAW
, PROT_TELNET
, PROT_RLOGIN
, PROT_SSH
} protocol
;
227 int ping_interval
; /* in seconds */
230 char proxy_exclude_list
[512];
231 enum { PROXYDNS_NO
, PROXYDNS_AUTO
, PROXYDNS_YES
} proxy_dns
;
232 int even_proxy_localhost
;
233 enum { PROXY_NONE
, PROXY_HTTP
, PROXY_SOCKS
, PROXY_TELNET
} proxy_type
;
234 char proxy_host
[512];
236 char proxy_username
[32];
237 char proxy_password
[32];
238 char proxy_telnet_command
[512];
239 int proxy_socks_version
;
241 char remote_cmd
[512];
242 char remote_cmd2
[512]; /* fallback if the first fails
243 * (used internally for scp) */
244 char *remote_cmd_ptr
; /* might point to a larger command
245 * but never for loading/saving */
246 char *remote_cmd_ptr2
; /* might point to a larger command
247 * but never for loading/saving */
251 int change_username
; /* allow username switching in SSH2 */
252 int ssh_cipherlist
[CIPHER_MAX
];
253 char keyfile
[FILENAME_MAX
];
254 int sshprot
; /* use v1 or v2 when both available */
255 int ssh2_des_cbc
; /* "des-cbc" nonstandard SSH2 cipher */
258 int ssh_subsys
; /* run a subsystem rather than a command */
259 int ssh_subsys2
; /* fallback to go with remote_cmd2 */
263 char environmt
[1024]; /* VAR\tvalue\0VAR\tvalue\0\0 */
265 char localusername
[100];
268 /* Keyboard options */
272 int no_applic_c
; /* totally disable app cursor keys */
273 int no_applic_k
; /* totally disable app keypad */
274 int no_mouse_rep
; /* totally disable mouse reporting */
275 int no_remote_resize
; /* disable remote resizing */
276 int no_alt_screen
; /* disable alternate screen */
277 int no_remote_wintitle
; /* disable remote retitling */
278 int no_dbackspace
; /* disable destructive backspace */
279 int no_remote_charset
; /* disable remote charset config */
285 int alt_f4
; /* is it special? */
286 int alt_space
; /* is it special? */
287 int alt_only
; /* is it special? */
291 int fullscreenonaltenter
;
296 char wintitle
[256]; /* initial window title */
297 /* Terminal options */
302 int cursor_type
; /* 0=block 1=underline 2=vertical */
305 BELL_DISABLED
, BELL_DEFAULT
, BELL_VISUAL
, BELL_WAVEFILE
308 B_IND_DISABLED
, B_IND_FLASH
, B_IND_STEADY
310 int bellovl
; /* bell overload protection active? */
311 int bellovl_n
; /* number of bells to cause overload */
312 int bellovl_t
; /* time interval for overload (seconds) */
313 int bellovl_s
; /* period of silence to re-enable bell (s) */
314 char bell_wavefile
[FILENAME_MAX
];
316 int scrollbar_in_fullscreen
;
317 enum { RESIZE_TERM
, RESIZE_DISABLED
, RESIZE_FONT
, RESIZE_EITHER
} resize_action
;
326 char logfilename
[FILENAME_MAX
];
332 char answerback
[256];
337 unsigned char colours
[22][3];
338 /* Selection options */
347 char line_codepage
[128];
348 int xlat_capslockcyr
;
351 char x11_display
[128];
353 /* port forwarding */
354 int lport_acceptall
; /* accept conns from hosts other than localhost */
355 int rport_acceptall
; /* same for remote forwarded ports (SSH2 only) */
356 char portfwd
[1024]; /* [LR]localport\thost:port\000[LR]localport\thost:port\000\000 */
357 /* SSH bug compatibility modes */
359 BUG_AUTO
, BUG_OFF
, BUG_ON
360 } sshbug_ignore1
, sshbug_plainpw1
, sshbug_rsa1
,
361 sshbug_hmac2
, sshbug_derivekey2
, sshbug_rsapad2
,
363 /* Options for pterm. Should split out into platform-dependent part. */
366 int scrollbar_on_left
;
369 char wideboldfont
[256];
370 int shadowboldoffset
;
374 * You can compile with -DTELNET_DEFAULT to have telnet by default
375 * (otherwise SSH is the default).
377 #ifdef TELNET_DEFAULT
378 #define DEFAULT_PROTOCOL PROT_TELNET
379 #define DEFAULT_PORT 23
381 #define DEFAULT_PROTOCOL PROT_SSH
382 #define DEFAULT_PORT 22
386 * Some global flags denoting the type of application.
388 * FLAG_VERBOSE is set when the user requests verbose details.
390 * FLAG_STDERR is set in command-line applications (which have a
391 * functioning stderr that it makes sense to write to) and not in
392 * GUI applications (which don't).
394 * FLAG_INTERACTIVE is set when a full interactive shell session is
395 * being run, _either_ because no remote command has been provided
396 * _or_ because the application is GUI and can't run non-
399 * These flags describe the type of _application_ - they wouldn't
400 * vary between individual sessions - and so it's OK to have this
401 * variable be GLOBAL.
403 #define FLAG_VERBOSE 0x0001
404 #define FLAG_STDERR 0x0002
405 #define FLAG_INTERACTIVE 0x0004
409 * Likewise, these two variables are set up when the application
410 * initialises, and inform all default-settings accesses after
413 GLOBAL
int default_protocol
;
414 GLOBAL
int default_port
;
416 struct RSAKey
; /* be a little careful of scope */
419 * Exports from window.c.
421 void request_resize(void *frontend
, int, int);
422 void do_text(Context
, int, int, char *, int, unsigned long, int);
423 void do_cursor(Context
, int, int, char *, int, unsigned long, int);
424 int char_width(Context ctx
, int uc
);
425 #ifdef OPTIMISE_SCROLL
426 void do_scroll(void *, int, int, int);
428 void set_title(void *frontend
, char *);
429 void set_icon(void *frontend
, char *);
430 void set_sbar(void *frontend
, int, int, int);
431 Context
get_ctx(void *frontend
);
432 void free_ctx(Context
);
433 void palette_set(void *frontend
, int, int, int, int);
434 void palette_reset(void *frontend
);
435 void write_aclip(void *frontend
, char *, int, int);
436 void write_clip(void *frontend
, wchar_t *, int, int);
437 void get_clip(void *frontend
, wchar_t **, int *);
438 void optimised_move(void *frontend
, int, int, int);
439 void set_raw_mouse_mode(void *frontend
, int);
440 Mouse_Button
translate_button(void *frontend
, Mouse_Button b
);
441 void connection_fatal(void *frontend
, char *, ...);
442 void fatalbox(char *, ...);
443 void modalfatalbox(char *, ...);
445 #pragma noreturn(fatalbox)
446 #pragma noreturn(modalfatalbox)
448 void beep(void *frontend
, int);
449 void begin_session(void *frontend
);
450 void sys_cursor(void *frontend
, int x
, int y
);
451 void request_paste(void *frontend
);
452 void frontend_keypress(void *frontend
);
453 void ldisc_update(void *frontend
, int echo
, int edit
);
454 #define OPTIMISE_IS_SCROLL 1
456 void set_iconic(void *frontend
, int iconic
);
457 void move_window(void *frontend
, int x
, int y
);
458 void set_zorder(void *frontend
, int top
);
459 void refresh_window(void *frontend
);
460 void set_zoomed(void *frontend
, int zoomed
);
461 int is_iconic(void *frontend
);
462 void get_window_pos(void *frontend
, int *x
, int *y
);
463 void get_window_pixels(void *frontend
, int *x
, int *y
);
464 char *get_window_title(void *frontend
, int icon
);
466 void cleanup_exit(int);
469 * Exports from noise.c.
471 void noise_get_heavy(void (*func
) (void *, int));
472 void noise_get_light(void (*func
) (void *, int));
473 void noise_regular(void);
474 void noise_ultralight(unsigned long data
);
475 void random_save_seed(void);
476 void random_destroy_seed(void);
479 * Exports from settings.c.
481 void save_settings(char *section
, int do_host
, Config
* cfg
);
482 void load_settings(char *section
, int do_host
, Config
* cfg
);
483 void load_open_settings(void *sesskey
, int do_host
, Config
*cfg
);
484 void get_sesslist(struct sesslist
*, int allocate
);
485 void do_defaults(char *, Config
*);
486 void registry_cleanup(void);
489 * Functions used by settings.c to provide platform-specific
492 * (The integer one is expected to return `def' if it has no clear
493 * opinion of its own. This is because there's no integer value
494 * which I can reliably set aside to indicate `nil'. The string
495 * function is perfectly all right returning NULL, of course.)
497 char *platform_default_s(const char *name
);
498 int platform_default_i(const char *name
, int def
);
501 * Exports from terminal.c.
504 Terminal
*term_init(Config
*, struct unicode_data
*, void *);
505 void term_size(Terminal
*, int, int, int);
506 void term_out(Terminal
*);
507 void term_paint(Terminal
*, Context
, int, int, int, int, int);
508 void term_scroll(Terminal
*, int, int);
509 void term_pwron(Terminal
*);
510 void term_clrsb(Terminal
*);
511 void term_mouse(Terminal
*, Mouse_Button
, Mouse_Action
, int,int,int,int,int);
512 void term_deselect(Terminal
*);
513 void term_update(Terminal
*);
514 void term_invalidate(Terminal
*);
515 void term_blink(Terminal
*, int set_cursor
);
516 void term_do_paste(Terminal
*);
517 int term_paste_pending(Terminal
*);
518 void term_paste(Terminal
*);
519 void term_nopaste(Terminal
*);
520 int term_ldisc(Terminal
*, int option
);
521 void term_copyall(Terminal
*);
522 void term_reconfig(Terminal
*, Config
*);
523 void term_seen_key_event(Terminal
*);
524 int from_backend(void *, int is_stderr
, char *data
, int len
);
525 void term_provide_resize_fn(Terminal
*term
,
526 void (*resize_fn
)(void *, int, int),
528 void term_provide_logctx(Terminal
*term
, void *logctx
);
531 * Exports from logging.c.
533 void *log_init(void *frontend
, Config
*cfg
);
534 void log_reconfig(void *logctx
, Config
*cfg
);
535 void logfopen(void *logctx
);
536 void logfclose(void *logctx
);
537 void logtraffic(void *logctx
, unsigned char c
, int logmode
);
538 void log_eventlog(void *logctx
, char *string
);
539 enum { PKT_INCOMING
, PKT_OUTGOING
};
540 void log_packet(void *logctx
, int direction
, int type
,
541 char *texttype
, void *data
, int len
);
544 * Exports from testback.c
547 extern Backend null_backend
;
548 extern Backend loop_backend
;
551 * Exports from raw.c.
554 extern Backend raw_backend
;
557 * Exports from rlogin.c.
560 extern Backend rlogin_backend
;
563 * Exports from telnet.c.
566 extern Backend telnet_backend
;
569 * Exports from ssh.c. (NB the getline variables have to be GLOBAL
570 * so that PuTTYtel will still compile - otherwise it would depend
574 GLOBAL
int (*ssh_get_line
) (const char *prompt
, char *str
, int maxlen
,
576 GLOBAL
int ssh_getline_pw_only
;
577 extern Backend ssh_backend
;
580 * Exports from ldisc.c.
582 void *ldisc_create(Config
*, Terminal
*, Backend
*, void *, void *);
583 void ldisc_send(void *handle
, char *buf
, int len
, int interactive
);
586 * Exports from ldiscucs.c.
588 void lpage_send(void *, int codepage
, char *buf
, int len
, int interactive
);
589 void luni_send(void *, wchar_t * widebuf
, int len
, int interactive
);
592 * Exports from sshrand.c.
595 void random_add_noise(void *noise
, int length
);
596 void random_init(void);
597 int random_byte(void);
598 void random_get_savedata(void **data
, int *len
);
599 extern int random_active
;
602 * Exports from misc.c.
608 * Exports from version.c.
613 * Exports from unicode.c.
616 #define CP_UTF8 65001
618 /* void init_ucs(void); -- this is now in platform-specific headers */
619 int is_dbcs_leadbyte(int codepage
, char byte
);
620 int mb_to_wc(int codepage
, int flags
, char *mbstr
, int mblen
,
621 wchar_t *wcstr
, int wclen
);
622 int wc_to_mb(int codepage
, int flags
, wchar_t *wcstr
, int wclen
,
623 char *mbstr
, int mblen
, char *defchr
, int *defused
,
624 struct unicode_data
*ucsdata
);
625 wchar_t xlat_uskbd2cyrllic(int ch
);
626 int check_compose(int first
, int second
);
627 int decode_codepage(char *cp_name
);
628 char *cp_enumerate (int index
);
629 char *cp_name(int codepage
);
630 void get_unitab(int codepage
, wchar_t * unitab
, int ftype
);
633 * Exports from wcwidth.c
635 int wcwidth(wchar_t ucs
);
636 int wcswidth(const wchar_t *pwcs
, size_t n
);
639 * Exports from mscrypto.c
642 int crypto_startup();
643 void crypto_wrapup();
647 * Exports from pageantc.c
649 void agent_query(void *in
, int inlen
, void **out
, int *outlen
);
650 int agent_exists(void);
653 * Exports from wildcard.c
655 const char *wc_error(int value
);
656 int wc_match(const char *wildcard
, const char *target
);
657 int wc_unescape(char *output
, const char *wildcard
);
660 * Exports from windlg.c
662 void logevent(void *frontend
, char *);
663 void verify_ssh_host_key(void *frontend
, char *host
, int port
, char *keytype
,
664 char *keystr
, char *fingerprint
);
665 void askcipher(void *frontend
, char *ciphername
, int cs
);
666 int askappend(void *frontend
, char *filename
);
669 * Exports from console.c (that aren't equivalents to things in
672 extern int console_batch_mode
;
673 int console_get_line(const char *prompt
, char *str
, int maxlen
, int is_pw
);
676 * Exports from printing.c.
678 typedef struct printer_enum_tag printer_enum
;
679 typedef struct printer_job_tag printer_job
;
680 printer_enum
*printer_start_enum(int *nprinters
);
681 char *printer_get_name(printer_enum
*, int);
682 void printer_finish_enum(printer_enum
*);
683 printer_job
*printer_start_job(char *printer
);
684 void printer_job_data(printer_job
*, void *, int);
685 void printer_finish_job(printer_job
*);
688 * Exports from cmdline.c (and also cmdline_error(), which is
689 * defined differently in various places and required _by_
692 int cmdline_process_param(char *, char *, int, Config
*);
693 void cmdline_run_saved(Config
*);
694 extern char *cmdline_password
;
695 #define TOOLTYPE_FILETRANSFER 1
696 extern int cmdline_tooltype
;
698 void cmdline_error(char *, ...);
701 * X11 auth mechanisms we know about.
705 X11_MIT
, /* MIT-MAGIC-COOKIE-1 */
706 X11_XDM
, /* XDM-AUTHORIZATION-1 */
709 extern const char *const x11_authnames
[]; /* declared in x11fwd.c */