Fixed issue #2495: "Show Reflog" dialog shows empty action for "push" entries
[TortoiseGit.git] / src / TortoisePlink / PUTTY.H
blob3bd888a266ea0466012519a13221a9830db66506
1 #ifndef PUTTY_PUTTY_H\r
2 #define PUTTY_PUTTY_H\r
3 \r
4 #include <stddef.h>                    /* for wchar_t */\r
5 \r
6 /*\r
7  * Global variables. Most modules declare these `extern', but\r
8  * window.c will do `#define PUTTY_DO_GLOBALS' before including this\r
9  * module, and so will get them properly defined.\r
10  */\r
11 #ifndef GLOBAL\r
12 #ifdef PUTTY_DO_GLOBALS\r
13 #define GLOBAL\r
14 #else\r
15 #define GLOBAL extern\r
16 #endif\r
17 #endif\r
19 #ifndef DONE_TYPEDEFS\r
20 #define DONE_TYPEDEFS\r
21 typedef struct conf_tag Conf;\r
22 typedef struct backend_tag Backend;\r
23 typedef struct terminal_tag Terminal;\r
24 #endif\r
26 #include "puttyps.h"\r
27 #include "network.h"\r
28 #include "misc.h"\r
30 /*\r
31  * Fingerprints of the PGP master keys that can be used to establish a trust\r
32  * path between an executable and other files.\r
33  */\r
34 #define PGP_RSA_MASTER_KEY_FP \\r
35     "8F 15 97 DA 25 30 AB 0D  88 D1 92 54 11 CF 0C 4C"\r
36 #define PGP_DSA_MASTER_KEY_FP \\r
37     "313C 3E76 4B74 C2C5 F2AE  83A8 4F5E 6DF5 6A93 B34E"\r
39 /* Three attribute types: \r
40  * The ATTRs (normal attributes) are stored with the characters in\r
41  * the main display arrays\r
42  *\r
43  * The TATTRs (temporary attributes) are generated on the fly, they\r
44  * can overlap with characters but not with normal attributes.\r
45  *\r
46  * The LATTRs (line attributes) are an entirely disjoint space of\r
47  * flags.\r
48  * \r
49  * The DATTRs (display attributes) are internal to terminal.c (but\r
50  * defined here because their values have to match the others\r
51  * here); they reuse the TATTR_* space but are always masked off\r
52  * before sending to the front end.\r
53  *\r
54  * ATTR_INVALID is an illegal colour combination.\r
55  */\r
57 #define TATTR_ACTCURS       0x40000000UL      /* active cursor (block) */\r
58 #define TATTR_PASCURS       0x20000000UL      /* passive cursor (box) */\r
59 #define TATTR_RIGHTCURS     0x10000000UL      /* cursor-on-RHS */\r
60 #define TATTR_COMBINING     0x80000000UL      /* combining characters */\r
62 #define DATTR_STARTRUN      0x80000000UL   /* start of redraw run */\r
64 #define TDATTR_MASK         0xF0000000UL\r
65 #define TATTR_MASK (TDATTR_MASK)\r
66 #define DATTR_MASK (TDATTR_MASK)\r
68 #define LATTR_NORM   0x00000000UL\r
69 #define LATTR_WIDE   0x00000001UL\r
70 #define LATTR_TOP    0x00000002UL\r
71 #define LATTR_BOT    0x00000003UL\r
72 #define LATTR_MODE   0x00000003UL\r
73 #define LATTR_WRAPPED 0x00000010UL     /* this line wraps to next */\r
74 #define LATTR_WRAPPED2 0x00000020UL    /* with WRAPPED: CJK wide character\r
75                                           wrapped to next line, so last\r
76                                           single-width cell is empty */\r
78 #define ATTR_INVALID 0x03FFFFU\r
80 /* Like Linux use the F000 page for direct to font. */\r
81 #define CSET_OEMCP   0x0000F000UL      /* OEM Codepage DTF */\r
82 #define CSET_ACP     0x0000F100UL      /* Ansi Codepage DTF */\r
84 /* These are internal use overlapping with the UTF-16 surrogates */\r
85 #define CSET_ASCII   0x0000D800UL      /* normal ASCII charset ESC ( B */\r
86 #define CSET_LINEDRW 0x0000D900UL      /* line drawing charset ESC ( 0 */\r
87 #define CSET_SCOACS  0x0000DA00UL      /* SCO Alternate charset */\r
88 #define CSET_GBCHR   0x0000DB00UL      /* UK variant   charset ESC ( A */\r
89 #define CSET_MASK    0xFFFFFF00UL      /* Character set mask */\r
91 #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)\r
92 #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xF000)\r
94 #define UCSERR       (CSET_LINEDRW|'a') /* UCS Format error character. */\r
95 /*\r
96  * UCSWIDE is a special value used in the terminal data to signify\r
97  * the character cell containing the right-hand half of a CJK wide\r
98  * character. We use 0xDFFF because it's part of the surrogate\r
99  * range and hence won't be used for anything else (it's impossible\r
100  * to input it via UTF-8 because our UTF-8 decoder correctly\r
101  * rejects surrogates).\r
102  */\r
103 #define UCSWIDE      0xDFFF\r
105 #define ATTR_NARROW  0x800000U\r
106 #define ATTR_WIDE    0x400000U\r
107 #define ATTR_BOLD    0x040000U\r
108 #define ATTR_UNDER   0x080000U\r
109 #define ATTR_REVERSE 0x100000U\r
110 #define ATTR_BLINK   0x200000U\r
111 #define ATTR_FGMASK  0x0001FFU\r
112 #define ATTR_BGMASK  0x03FE00U\r
113 #define ATTR_COLOURS 0x03FFFFU\r
114 #define ATTR_FGSHIFT 0\r
115 #define ATTR_BGSHIFT 9\r
117 /*\r
118  * The definitive list of colour numbers stored in terminal\r
119  * attribute words is kept here. It is:\r
120  * \r
121  *  - 0-7 are ANSI colours (KRGYBMCW).\r
122  *  - 8-15 are the bold versions of those colours.\r
123  *  - 16-255 are the remains of the xterm 256-colour mode (a\r
124  *    216-colour cube with R at most significant and B at least,\r
125  *    followed by a uniform series of grey shades running between\r
126  *    black and white but not including either on grounds of\r
127  *    redundancy).\r
128  *  - 256 is default foreground\r
129  *  - 257 is default bold foreground\r
130  *  - 258 is default background\r
131  *  - 259 is default bold background\r
132  *  - 260 is cursor foreground\r
133  *  - 261 is cursor background\r
134  */\r
136 #define ATTR_DEFFG   (256 << ATTR_FGSHIFT)\r
137 #define ATTR_DEFBG   (258 << ATTR_BGSHIFT)\r
138 #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)\r
140 struct sesslist {\r
141     int nsessions;\r
142     char **sessions;\r
143     char *buffer;                      /* so memory can be freed later */\r
144 };\r
146 struct unicode_data {\r
147     char **uni_tbl;\r
148     int dbcs_screenfont;\r
149     int font_codepage;\r
150     int line_codepage;\r
151     wchar_t unitab_scoacs[256];\r
152     wchar_t unitab_line[256];\r
153     wchar_t unitab_font[256];\r
154     wchar_t unitab_xterm[256];\r
155     wchar_t unitab_oemcp[256];\r
156     unsigned char unitab_ctrl[256];\r
157 };\r
159 #define LGXF_OVR  1                    /* existing logfile overwrite */\r
160 #define LGXF_APN  0                    /* existing logfile append */\r
161 #define LGXF_ASK -1                    /* existing logfile ask */\r
162 #define LGTYP_NONE  0                  /* logmode: no logging */\r
163 #define LGTYP_ASCII 1                  /* logmode: pure ascii */\r
164 #define LGTYP_DEBUG 2                  /* logmode: all chars of traffic */\r
165 #define LGTYP_PACKETS 3                /* logmode: SSH data packets */\r
166 #define LGTYP_SSHRAW 4                 /* logmode: SSH raw data */\r
168 typedef enum {\r
169     /* Actual special commands. Originally Telnet, but some codes have\r
170      * been re-used for similar specials in other protocols. */\r
171     TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,\r
172     TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF, TS_LECHO, TS_RECHO, TS_PING,\r
173     TS_EOL,\r
174     /* Special command for SSH. */\r
175     TS_REKEY,\r
176     /* POSIX-style signals. (not Telnet) */\r
177     TS_SIGABRT, TS_SIGALRM, TS_SIGFPE,  TS_SIGHUP,  TS_SIGILL,\r
178     TS_SIGINT,  TS_SIGKILL, TS_SIGPIPE, TS_SIGQUIT, TS_SIGSEGV,\r
179     TS_SIGTERM, TS_SIGUSR1, TS_SIGUSR2,\r
180     /* Pseudo-specials used for constructing the specials menu. */\r
181     TS_SEP,         /* Separator */\r
182     TS_SUBMENU,     /* Start a new submenu with specified name */\r
183     TS_EXITMENU     /* Exit current submenu or end of specials */\r
184 } Telnet_Special;\r
186 struct telnet_special {\r
187     const char *name;\r
188     int code;\r
189 };\r
191 typedef enum {\r
192     MBT_NOTHING,\r
193     MBT_LEFT, MBT_MIDDLE, MBT_RIGHT,   /* `raw' button designations */\r
194     MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */\r
195     MBT_WHEEL_UP, MBT_WHEEL_DOWN       /* mouse wheel */\r
196 } Mouse_Button;\r
198 typedef enum {\r
199     MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE\r
200 } Mouse_Action;\r
202 /* Keyboard modifiers -- keys the user is actually holding down */\r
204 #define PKM_SHIFT       0x01\r
205 #define PKM_CONTROL     0x02\r
206 #define PKM_META        0x04\r
207 #define PKM_ALT         0x08\r
209 /* Keyboard flags that aren't really modifiers */\r
210 #define PKF_CAPSLOCK    0x10\r
211 #define PKF_NUMLOCK     0x20\r
212 #define PKF_REPEAT      0x40\r
214 /* Stand-alone keysyms for function keys */\r
216 typedef enum {\r
217     PK_NULL,            /* No symbol for this key */\r
218     /* Main keypad keys */\r
219     PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,\r
220     /* Editing keys */\r
221     PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,\r
222     /* Cursor keys */\r
223     PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,\r
224     /* Numeric keypad */                        /* Real one looks like: */\r
225     PK_PF1, PK_PF2, PK_PF3, PK_PF4,             /* PF1 PF2 PF3 PF4 */\r
226     PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL,       /*  7   8   9   -  */\r
227     PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4,     /*  4   5   6   ,  */\r
228     PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9,     /*  1   2   3  en- */\r
229     PK_KPBIGPLUS, PK_KPENTER,                   /*    0     .  ter */\r
230     /* Top row */\r
231     PK_F1,  PK_F2,  PK_F3,  PK_F4,  PK_F5,\r
232     PK_F6,  PK_F7,  PK_F8,  PK_F9,  PK_F10,\r
233     PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,\r
234     PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,\r
235     PK_PAUSE\r
236 } Key_Sym;\r
238 #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)\r
239 #define PK_ISCURSOR(k)  ((k) >= PK_UP && (k) <= PK_REST)\r
240 #define PK_ISKEYPAD(k)  ((k) >= PK_PF1 && (k) <= PK_KPENTER)\r
241 #define PK_ISFKEY(k)    ((k) >= PK_F1 && (k) <= PK_F20)\r
243 enum {\r
244     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE\r
245 };\r
247 enum {\r
248     /*\r
249      * SSH-2 key exchange algorithms\r
250      */\r
251     KEX_WARN,\r
252     KEX_DHGROUP1,\r
253     KEX_DHGROUP14,\r
254     KEX_DHGEX,\r
255     KEX_RSA,\r
256     KEX_MAX\r
257 };\r
259 enum {\r
260     /*\r
261      * SSH ciphers (both SSH-1 and SSH-2)\r
262      */\r
263     CIPHER_WARN,                       /* pseudo 'cipher' */\r
264     CIPHER_3DES,\r
265     CIPHER_BLOWFISH,\r
266     CIPHER_AES,                        /* (SSH-2 only) */\r
267     CIPHER_DES,\r
268     CIPHER_ARCFOUR,\r
269     CIPHER_MAX                         /* no. ciphers (inc warn) */\r
270 };\r
272 enum {\r
273     /*\r
274      * Several different bits of the PuTTY configuration seem to be\r
275      * three-way settings whose values are `always yes', `always\r
276      * no', and `decide by some more complex automated means'. This\r
277      * is true of line discipline options (local echo and line\r
278      * editing), proxy DNS, Close On Exit, and SSH server bug\r
279      * workarounds. Accordingly I supply a single enum here to deal\r
280      * with them all.\r
281      */\r
282     FORCE_ON, FORCE_OFF, AUTO\r
283 };\r
285 enum {\r
286     /*\r
287      * Proxy types.\r
288      */\r
289     PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,\r
290     PROXY_HTTP, PROXY_TELNET, PROXY_CMD\r
291 };\r
293 enum {\r
294     /*\r
295      * Line discipline options which the backend might try to control.\r
296      */\r
297     LD_EDIT,                           /* local line editing */\r
298     LD_ECHO                            /* local echo */\r
299 };\r
301 enum {\r
302     /* Actions on remote window title query */\r
303     TITLE_NONE, TITLE_EMPTY, TITLE_REAL\r
304 };\r
306 enum {\r
307     /* Protocol back ends. (CONF_protocol) */\r
308     PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,\r
309     /* PROT_SERIAL is supported on a subset of platforms, but it doesn't\r
310      * hurt to define it globally. */\r
311     PROT_SERIAL\r
312 };\r
314 enum {\r
315     /* Bell settings (CONF_beep) */\r
316     BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER\r
317 };\r
319 enum {\r
320     /* Taskbar flashing indication on bell (CONF_beep_ind) */\r
321     B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY\r
322 };\r
324 enum {\r
325     /* Resize actions (CONF_resize_action) */\r
326     RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER\r
327 };\r
329 enum {\r
330     /* Function key types (CONF_funky_type) */\r
331     FUNKY_TILDE,\r
332     FUNKY_LINUX,\r
333     FUNKY_XTERM,\r
334     FUNKY_VT400,\r
335     FUNKY_VT100P,\r
336     FUNKY_SCO\r
337 };\r
339 enum {\r
340     FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE\r
341 };\r
343 enum {\r
344     SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE\r
345 };\r
347 enum {\r
348     SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR\r
349 };\r
351 /*\r
352  * Tables of string <-> enum value mappings used in settings.c.\r
353  * Defined here so that backends can export their GSS library tables\r
354  * to the cross-platform settings code.\r
355  */\r
356 struct keyvalwhere {\r
357     /*\r
358      * Two fields which define a string and enum value to be\r
359      * equivalent to each other.\r
360      */\r
361     char *s;\r
362     int v;\r
364     /*\r
365      * The next pair of fields are used by gprefs() in settings.c to\r
366      * arrange that when it reads a list of strings representing a\r
367      * preference list and translates it into the corresponding list\r
368      * of integers, strings not appearing in the list are entered in a\r
369      * configurable position rather than uniformly at the end.\r
370      */\r
372     /*\r
373      * 'vrel' indicates which other value in the list to place this\r
374      * element relative to. It should be a value that has occurred in\r
375      * a 'v' field of some other element of the array, or -1 to\r
376      * indicate that we simply place relative to one or other end of\r
377      * the list.\r
378      *\r
379      * gprefs will try to process the elements in an order which makes\r
380      * this field work (i.e. so that the element referenced has been\r
381      * added before processing this one).\r
382      */\r
383     int vrel;\r
385     /*\r
386      * 'where' indicates whether to place the new value before or\r
387      * after the one referred to by vrel. -1 means before; +1 means\r
388      * after.\r
389      *\r
390      * When vrel is -1, this also implicitly indicates which end of\r
391      * the array to use. So vrel=-1, where=-1 means to place _before_\r
392      * some end of the list (hence, at the last element); vrel=-1,\r
393      * where=+1 means to place _after_ an end (hence, at the first).\r
394      */\r
395     int where;\r
396 };\r
398 #ifndef NO_GSSAPI\r
399 extern const int ngsslibs;\r
400 extern const char *const gsslibnames[]; /* for displaying in configuration */\r
401 extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */\r
402 #endif\r
404 extern const char *const ttymodes[];\r
406 enum {\r
407     /*\r
408      * Network address types. Used for specifying choice of IPv4/v6\r
409      * in config; also used in proxy.c to indicate whether a given\r
410      * host name has already been resolved or will be resolved at\r
411      * the proxy end.\r
412      */\r
413     ADDRTYPE_UNSPEC, ADDRTYPE_IPV4, ADDRTYPE_IPV6, ADDRTYPE_NAME\r
414 };\r
416 struct backend_tag {\r
417     const char *(*init) (void *frontend_handle, void **backend_handle,\r
418                          Conf *conf, char *host, int port, char **realhost,\r
419                          int nodelay, int keepalive);\r
420     void (*free) (void *handle);\r
421     /* back->reconfig() passes in a replacement configuration. */\r
422     void (*reconfig) (void *handle, Conf *conf);\r
423     /* back->send() returns the current amount of buffered data. */\r
424     int (*send) (void *handle, char *buf, int len);\r
425     /* back->sendbuffer() does the same thing but without attempting a send */\r
426     int (*sendbuffer) (void *handle);\r
427     void (*size) (void *handle, int width, int height);\r
428     void (*special) (void *handle, Telnet_Special code);\r
429     const struct telnet_special *(*get_specials) (void *handle);\r
430     int (*connected) (void *handle);\r
431     int (*exitcode) (void *handle);\r
432     /* If back->sendok() returns FALSE, data sent to it from the frontend\r
433      * may be lost. */\r
434     int (*sendok) (void *handle);\r
435     int (*ldisc) (void *handle, int);\r
436     void (*provide_ldisc) (void *handle, void *ldisc);\r
437     void (*provide_logctx) (void *handle, void *logctx);\r
438     /*\r
439      * back->unthrottle() tells the back end that the front end\r
440      * buffer is clearing.\r
441      */\r
442     void (*unthrottle) (void *handle, int);\r
443     int (*cfg_info) (void *handle);\r
444     char *name;\r
445     int protocol;\r
446     int default_port;\r
447 };\r
449 extern Backend *backends[];\r
451 /*\r
452  * Suggested default protocol provided by the backend link module.\r
453  * The application is free to ignore this.\r
454  */\r
455 extern const int be_default_protocol;\r
457 /*\r
458  * Name of this particular application, for use in the config box\r
459  * and other pieces of text.\r
460  */\r
461 extern const char *const appname;\r
463 /*\r
464  * Some global flags denoting the type of application.\r
465  * \r
466  * FLAG_VERBOSE is set when the user requests verbose details.\r
467  * \r
468  * FLAG_STDERR is set in command-line applications (which have a\r
469  * functioning stderr that it makes sense to write to) and not in\r
470  * GUI applications (which don't).\r
471  * \r
472  * FLAG_INTERACTIVE is set when a full interactive shell session is\r
473  * being run, _either_ because no remote command has been provided\r
474  * _or_ because the application is GUI and can't run non-\r
475  * interactively.\r
476  * \r
477  * These flags describe the type of _application_ - they wouldn't\r
478  * vary between individual sessions - and so it's OK to have this\r
479  * variable be GLOBAL.\r
480  * \r
481  * Note that additional flags may be defined in platform-specific\r
482  * headers. It's probably best if those ones start from 0x1000, to\r
483  * avoid collision.\r
484  */\r
485 #define FLAG_VERBOSE     0x0001\r
486 #define FLAG_STDERR      0x0002\r
487 #define FLAG_INTERACTIVE 0x0004\r
488 GLOBAL int flags;\r
490 /*\r
491  * Likewise, these two variables are set up when the application\r
492  * initialises, and inform all default-settings accesses after\r
493  * that.\r
494  */\r
495 GLOBAL int default_protocol;\r
496 GLOBAL int default_port;\r
498 /*\r
499  * This is set TRUE by cmdline.c iff a session is loaded with "-load".\r
500  */\r
501 GLOBAL int loaded_session;\r
502 /*\r
503  * This is set to the name of the loaded session.\r
504  */\r
505 GLOBAL char *cmdline_session_name;\r
507 struct RSAKey;                         /* be a little careful of scope */\r
509 /*\r
510  * Mechanism for getting text strings such as usernames and passwords\r
511  * from the front-end.\r
512  * The fields are mostly modelled after SSH's keyboard-interactive auth.\r
513  * FIXME We should probably mandate a character set/encoding (probably UTF-8).\r
514  *\r
515  * Since many of the pieces of text involved may be chosen by the server,\r
516  * the caller must take care to ensure that the server can't spoof locally-\r
517  * generated prompts such as key passphrase prompts. Some ground rules:\r
518  *  - If the front-end needs to truncate a string, it should lop off the\r
519  *    end.\r
520  *  - The front-end should filter out any dangerous characters and\r
521  *    generally not trust the strings. (But \n is required to behave\r
522  *    vaguely sensibly, at least in `instruction', and ideally in\r
523  *    `prompt[]' too.)\r
524  */\r
525 typedef struct {\r
526     char *prompt;\r
527     int echo;\r
528     /*\r
529      * 'result' must be a dynamically allocated array of exactly\r
530      * 'resultsize' chars. The code for actually reading input may\r
531      * realloc it bigger (and adjust resultsize accordingly) if it has\r
532      * to. The caller should free it again when finished with it.\r
533      *\r
534      * If resultsize==0, then result may be NULL. When setting up a\r
535      * prompt_t, it's therefore easiest to initialise them this way,\r
536      * which means all actual allocation is done by the callee. This\r
537      * is what add_prompt does.\r
538      */\r
539     char *result;\r
540     size_t resultsize;\r
541 } prompt_t;\r
542 typedef struct {\r
543     /*\r
544      * Indicates whether the information entered is to be used locally\r
545      * (for instance a key passphrase prompt), or is destined for the wire.\r
546      * This is a hint only; the front-end is at liberty not to use this\r
547      * information (so the caller should ensure that the supplied text is\r
548      * sufficient).\r
549      */\r
550     int to_server;\r
551     char *name;         /* Short description, perhaps for dialog box title */\r
552     int name_reqd;      /* Display of `name' required or optional? */\r
553     char *instruction;  /* Long description, maybe with embedded newlines */\r
554     int instr_reqd;     /* Display of `instruction' required or optional? */\r
555     size_t n_prompts;   /* May be zero (in which case display the foregoing,\r
556                          * if any, and return success) */\r
557     prompt_t **prompts;\r
558     void *frontend;\r
559     void *data;         /* slot for housekeeping data, managed by\r
560                          * get_userpass_input(); initially NULL */\r
561 } prompts_t;\r
562 prompts_t *new_prompts(void *frontend);\r
563 void add_prompt(prompts_t *p, char *promptstr, int echo);\r
564 void prompt_set_result(prompt_t *pr, const char *newstr);\r
565 void prompt_ensure_result_size(prompt_t *pr, int len);\r
566 /* Burn the evidence. (Assumes _all_ strings want free()ing.) */\r
567 void free_prompts(prompts_t *p);\r
569 /*\r
570  * Exports from the front end.\r
571  */\r
572 void request_resize(void *frontend, int, int);\r
573 void do_text(Context, int, int, wchar_t *, int, unsigned long, int);\r
574 void do_cursor(Context, int, int, wchar_t *, int, unsigned long, int);\r
575 int char_width(Context ctx, int uc);\r
576 #ifdef OPTIMISE_SCROLL\r
577 void do_scroll(Context, int, int, int);\r
578 #endif\r
579 void set_title(void *frontend, char *);\r
580 void set_icon(void *frontend, char *);\r
581 void set_sbar(void *frontend, int, int, int);\r
582 Context get_ctx(void *frontend);\r
583 void free_ctx(Context);\r
584 void palette_set(void *frontend, int, int, int, int);\r
585 void palette_reset(void *frontend);\r
586 void write_aclip(void *frontend, char *, int, int);\r
587 void write_clip(void *frontend, wchar_t *, int *, int, int);\r
588 void get_clip(void *frontend, wchar_t **, int *);\r
589 void optimised_move(void *frontend, int, int, int);\r
590 void set_raw_mouse_mode(void *frontend, int);\r
591 void connection_fatal(void *frontend, char *, ...);\r
592 void nonfatal(char *, ...);\r
593 void fatalbox(char *, ...);\r
594 void modalfatalbox(char *, ...);\r
595 #ifdef macintosh\r
596 #pragma noreturn(fatalbox)\r
597 #pragma noreturn(modalfatalbox)\r
598 #endif\r
599 void do_beep(void *frontend, int);\r
600 void begin_session(void *frontend);\r
601 void sys_cursor(void *frontend, int x, int y);\r
602 void request_paste(void *frontend);\r
603 void frontend_keypress(void *frontend);\r
604 void ldisc_update(void *frontend, int echo, int edit);\r
605 /* It's the backend's responsibility to invoke this at the start of a\r
606  * connection, if necessary; it can also invoke it later if the set of\r
607  * special commands changes. It does not need to invoke it at session\r
608  * shutdown. */\r
609 void update_specials_menu(void *frontend);\r
610 int from_backend(void *frontend, int is_stderr, const char *data, int len);\r
611 int from_backend_untrusted(void *frontend, const char *data, int len);\r
612 /* Called when the back end wants to indicate that EOF has arrived on\r
613  * the server-to-client stream. Returns FALSE to indicate that we\r
614  * intend to keep the session open in the other direction, or TRUE to\r
615  * indicate that if they're closing so are we. */\r
616 int from_backend_eof(void *frontend);\r
617 void notify_remote_exit(void *frontend);\r
618 /* Get a sensible value for a tty mode. NULL return = don't set.\r
619  * Otherwise, returned value should be freed by caller. */\r
620 char *get_ttymode(void *frontend, const char *mode);\r
621 /*\r
622  * >0 = `got all results, carry on'\r
623  * 0  = `user cancelled' (FIXME distinguish "give up entirely" and "next auth"?)\r
624  * <0 = `please call back later with more in/inlen'\r
625  */\r
626 int get_userpass_input(prompts_t *p, unsigned char *in, int inlen);\r
627 #define OPTIMISE_IS_SCROLL 1\r
629 void set_iconic(void *frontend, int iconic);\r
630 void move_window(void *frontend, int x, int y);\r
631 void set_zorder(void *frontend, int top);\r
632 void refresh_window(void *frontend);\r
633 void set_zoomed(void *frontend, int zoomed);\r
634 int is_iconic(void *frontend);\r
635 void get_window_pos(void *frontend, int *x, int *y);\r
636 void get_window_pixels(void *frontend, int *x, int *y);\r
637 char *get_window_title(void *frontend, int icon);\r
638 /* Hint from backend to frontend about time-consuming operations.\r
639  * Initial state is assumed to be BUSY_NOT. */\r
640 enum {\r
641     BUSY_NOT,       /* Not busy, all user interaction OK */\r
642     BUSY_WAITING,   /* Waiting for something; local event loops still running\r
643                        so some local interaction (e.g. menus) OK, but network\r
644                        stuff is suspended */\r
645     BUSY_CPU        /* Locally busy (e.g. crypto); user interaction suspended */\r
646 };\r
647 void set_busy_status(void *frontend, int status);\r
649 void cleanup_exit(int);\r
651 /*\r
652  * Exports from conf.c, and a big enum (via parametric macro) of\r
653  * configuration option keys.\r
654  */\r
655 #define CONFIG_OPTIONS(X) \\r
656     /* X(value-type, subkey-type, keyword) */ \\r
657     X(STR, NONE, host) \\r
658     X(INT, NONE, port) \\r
659     X(INT, NONE, protocol) \\r
660     X(INT, NONE, addressfamily) \\r
661     X(INT, NONE, close_on_exit) \\r
662     X(INT, NONE, warn_on_close) \\r
663     X(INT, NONE, ping_interval) /* in seconds */ \\r
664     X(INT, NONE, tcp_nodelay) \\r
665     X(INT, NONE, tcp_keepalives) \\r
666     X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \\r
667     /* Proxy options */ \\r
668     X(STR, NONE, proxy_exclude_list) \\r
669     X(INT, NONE, proxy_dns) \\r
670     X(INT, NONE, even_proxy_localhost) \\r
671     X(INT, NONE, proxy_type) \\r
672     X(STR, NONE, proxy_host) \\r
673     X(INT, NONE, proxy_port) \\r
674     X(STR, NONE, proxy_username) \\r
675     X(STR, NONE, proxy_password) \\r
676     X(STR, NONE, proxy_telnet_command) \\r
677     /* SSH options */ \\r
678     X(STR, NONE, remote_cmd) \\r
679     X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \\r
680     X(INT, NONE, nopty) \\r
681     X(INT, NONE, compression) \\r
682     X(INT, INT, ssh_kexlist) \\r
683     X(INT, NONE, ssh_rekey_time) /* in minutes */ \\r
684     X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \\r
685     X(INT, NONE, tryagent) \\r
686     X(INT, NONE, agentfwd) \\r
687     X(INT, NONE, change_username) /* allow username switching in SSH-2 */ \\r
688     X(INT, INT, ssh_cipherlist) \\r
689     X(FILENAME, NONE, keyfile) \\r
690     X(INT, NONE, sshprot) /* use v1 or v2 when both available */ \\r
691     X(INT, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \\r
692     X(INT, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \\r
693     X(INT, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \\r
694     X(INT, NONE, try_tis_auth) \\r
695     X(INT, NONE, try_ki_auth) \\r
696     X(INT, NONE, try_gssapi_auth) /* attempt gssapi auth */ \\r
697     X(INT, NONE, gssapifwd) /* forward tgt via gss */ \\r
698     X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \\r
699     X(FILENAME, NONE, ssh_gss_custom) \\r
700     X(INT, NONE, ssh_subsys) /* run a subsystem rather than a command */ \\r
701     X(INT, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \\r
702     X(INT, NONE, ssh_no_shell) /* avoid running a shell */ \\r
703     X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \\r
704     X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \\r
705     /* Telnet options */ \\r
706     X(STR, NONE, termtype) \\r
707     X(STR, NONE, termspeed) \\r
708     X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \\r
709     X(STR, STR, environmt) \\r
710     X(STR, NONE, username) \\r
711     X(INT, NONE, username_from_env) \\r
712     X(STR, NONE, localusername) \\r
713     X(INT, NONE, rfc_environ) \\r
714     X(INT, NONE, passive_telnet) \\r
715     /* Serial port options */ \\r
716     X(STR, NONE, serline) \\r
717     X(INT, NONE, serspeed) \\r
718     X(INT, NONE, serdatabits) \\r
719     X(INT, NONE, serstopbits) \\r
720     X(INT, NONE, serparity) \\r
721     X(INT, NONE, serflow) \\r
722     /* Keyboard options */ \\r
723     X(INT, NONE, bksp_is_delete) \\r
724     X(INT, NONE, rxvt_homeend) \\r
725     X(INT, NONE, funky_type) \\r
726     X(INT, NONE, no_applic_c) /* totally disable app cursor keys */ \\r
727     X(INT, NONE, no_applic_k) /* totally disable app keypad */ \\r
728     X(INT, NONE, no_mouse_rep) /* totally disable mouse reporting */ \\r
729     X(INT, NONE, no_remote_resize) /* disable remote resizing */ \\r
730     X(INT, NONE, no_alt_screen) /* disable alternate screen */ \\r
731     X(INT, NONE, no_remote_wintitle) /* disable remote retitling */ \\r
732     X(INT, NONE, no_dbackspace) /* disable destructive backspace */ \\r
733     X(INT, NONE, no_remote_charset) /* disable remote charset config */ \\r
734     X(INT, NONE, remote_qtitle_action) /* remote win title query action */ \\r
735     X(INT, NONE, app_cursor) \\r
736     X(INT, NONE, app_keypad) \\r
737     X(INT, NONE, nethack_keypad) \\r
738     X(INT, NONE, telnet_keyboard) \\r
739     X(INT, NONE, telnet_newline) \\r
740     X(INT, NONE, alt_f4) /* is it special? */ \\r
741     X(INT, NONE, alt_space) /* is it special? */ \\r
742     X(INT, NONE, alt_only) /* is it special? */ \\r
743     X(INT, NONE, localecho) \\r
744     X(INT, NONE, localedit) \\r
745     X(INT, NONE, alwaysontop) \\r
746     X(INT, NONE, fullscreenonaltenter) \\r
747     X(INT, NONE, scroll_on_key) \\r
748     X(INT, NONE, scroll_on_disp) \\r
749     X(INT, NONE, erase_to_scrollback) \\r
750     X(INT, NONE, compose_key) \\r
751     X(INT, NONE, ctrlaltkeys) \\r
752     X(STR, NONE, wintitle) /* initial window title */ \\r
753     /* Terminal options */ \\r
754     X(INT, NONE, savelines) \\r
755     X(INT, NONE, dec_om) \\r
756     X(INT, NONE, wrap_mode) \\r
757     X(INT, NONE, lfhascr) \\r
758     X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \\r
759     X(INT, NONE, blink_cur) \\r
760     X(INT, NONE, beep) \\r
761     X(INT, NONE, beep_ind) \\r
762     X(INT, NONE, bellovl) /* bell overload protection active? */ \\r
763     X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \\r
764     X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \\r
765     X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \\r
766     X(FILENAME, NONE, bell_wavefile) \\r
767     X(INT, NONE, scrollbar) \\r
768     X(INT, NONE, scrollbar_in_fullscreen) \\r
769     X(INT, NONE, resize_action) \\r
770     X(INT, NONE, bce) \\r
771     X(INT, NONE, blinktext) \\r
772     X(INT, NONE, win_name_always) \\r
773     X(INT, NONE, width) \\r
774     X(INT, NONE, height) \\r
775     X(FONT, NONE, font) \\r
776     X(INT, NONE, font_quality) \\r
777     X(FILENAME, NONE, logfilename) \\r
778     X(INT, NONE, logtype) \\r
779     X(INT, NONE, logxfovr) \\r
780     X(INT, NONE, logflush) \\r
781     X(INT, NONE, logomitpass) \\r
782     X(INT, NONE, logomitdata) \\r
783     X(INT, NONE, hide_mouseptr) \\r
784     X(INT, NONE, sunken_edge) \\r
785     X(INT, NONE, window_border) \\r
786     X(STR, NONE, answerback) \\r
787     X(STR, NONE, printer) \\r
788     X(INT, NONE, arabicshaping) \\r
789     X(INT, NONE, bidi) \\r
790     /* Colour options */ \\r
791     X(INT, NONE, ansi_colour) \\r
792     X(INT, NONE, xterm_256_colour) \\r
793     X(INT, NONE, system_colour) \\r
794     X(INT, NONE, try_palette) \\r
795     X(INT, NONE, bold_style) \\r
796     X(INT, INT, colours) \\r
797     /* Selection options */ \\r
798     X(INT, NONE, mouse_is_xterm) \\r
799     X(INT, NONE, rect_select) \\r
800     X(INT, NONE, rawcnp) \\r
801     X(INT, NONE, rtf_paste) \\r
802     X(INT, NONE, mouse_override) \\r
803     X(INT, INT, wordness) \\r
804     /* translations */ \\r
805     X(INT, NONE, vtmode) \\r
806     X(STR, NONE, line_codepage) \\r
807     X(INT, NONE, cjk_ambig_wide) \\r
808     X(INT, NONE, utf8_override) \\r
809     X(INT, NONE, xlat_capslockcyr) \\r
810     /* X11 forwarding */ \\r
811     X(INT, NONE, x11_forward) \\r
812     X(STR, NONE, x11_display) \\r
813     X(INT, NONE, x11_auth) \\r
814     X(FILENAME, NONE, xauthfile) \\r
815     /* port forwarding */ \\r
816     X(INT, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \\r
817     X(INT, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \\r
818     /*                                                                \\r
819      * Subkeys for 'portfwd' can have the following forms:            \\r
820      *                                                                \\r
821      *   [LR]localport                                                \\r
822      *   [LR]localaddr:localport                                      \\r
823      *                                                                \\r
824      * Dynamic forwardings are indicated by an 'L' key, and the       \\r
825      * special value "D". For all other forwardings, the value        \\r
826      * should be of the form 'host:port'.                             \\r
827      */ \\r
828     X(STR, STR, portfwd) \\r
829     /* SSH bug compatibility modes */ \\r
830     X(INT, NONE, sshbug_ignore1) \\r
831     X(INT, NONE, sshbug_plainpw1) \\r
832     X(INT, NONE, sshbug_rsa1) \\r
833     X(INT, NONE, sshbug_hmac2) \\r
834     X(INT, NONE, sshbug_derivekey2) \\r
835     X(INT, NONE, sshbug_rsapad2) \\r
836     X(INT, NONE, sshbug_pksessid2) \\r
837     X(INT, NONE, sshbug_rekey2) \\r
838     X(INT, NONE, sshbug_maxpkt2) \\r
839     X(INT, NONE, sshbug_ignore2) \\r
840     X(INT, NONE, sshbug_winadj) \\r
841     X(INT, NONE, sshbug_chanreq) \\r
842     /*                                                                \\r
843      * ssh_simple means that we promise never to open any channel     \\r
844      * other than the main one, which means it can safely use a very  \\r
845      * large window in SSH-2.                                         \\r
846      */ \\r
847     X(INT, NONE, ssh_simple) \\r
848     X(INT, NONE, ssh_connection_sharing) \\r
849     X(INT, NONE, ssh_connection_sharing_upstream) \\r
850     X(INT, NONE, ssh_connection_sharing_downstream) \\r
851     /*\r
852      * ssh_manual_hostkeys is conceptually a set rather than a\r
853      * dictionary: the string subkeys are the important thing, and the\r
854      * actual values to which those subkeys map are all "".\r
855      */ \\r
856     X(STR, STR, ssh_manual_hostkeys) \\r
857     /* Options for pterm. Should split out into platform-dependent part. */ \\r
858     X(INT, NONE, stamp_utmp) \\r
859     X(INT, NONE, login_shell) \\r
860     X(INT, NONE, scrollbar_on_left) \\r
861     X(INT, NONE, shadowbold) \\r
862     X(FONT, NONE, boldfont) \\r
863     X(FONT, NONE, widefont) \\r
864     X(FONT, NONE, wideboldfont) \\r
865     X(INT, NONE, shadowboldoffset) \\r
866     X(INT, NONE, crhaslf) \\r
867     X(STR, NONE, winclass) \\r
869 /* Now define the actual enum of option keywords using that macro. */\r
870 #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,\r
871 enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };\r
872 #undef CONF_ENUM_DEF\r
874 #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */\r
876 /* Functions handling configuration structures. */\r
877 Conf *conf_new(void);                  /* create an empty configuration */\r
878 void conf_free(Conf *conf);\r
879 Conf *conf_copy(Conf *oldconf);\r
880 void conf_copy_into(Conf *dest, Conf *src);\r
881 /* Mandatory accessor functions: enforce by assertion that keys exist. */\r
882 int conf_get_int(Conf *conf, int key);\r
883 int conf_get_int_int(Conf *conf, int key, int subkey);\r
884 char *conf_get_str(Conf *conf, int key);   /* result still owned by conf */\r
885 char *conf_get_str_str(Conf *conf, int key, const char *subkey);\r
886 Filename *conf_get_filename(Conf *conf, int key);\r
887 FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */\r
888 /* Optional accessor function: return NULL if key does not exist. */\r
889 char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);\r
890 /* Accessor function to step through a string-subkeyed list.\r
891  * Returns the next subkey after the provided one, or the first if NULL.\r
892  * Returns NULL if there are none left.\r
893  * Both the return value and *subkeyout are still owned by conf. */\r
894 char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);\r
895 /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */\r
896 char *conf_get_str_nthstrkey(Conf *conf, int key, int n);\r
897 /* Functions to set entries in configuration. Always copy their inputs. */\r
898 void conf_set_int(Conf *conf, int key, int value);\r
899 void conf_set_int_int(Conf *conf, int key, int subkey, int value);\r
900 void conf_set_str(Conf *conf, int key, const char *value);\r
901 void conf_set_str_str(Conf *conf, int key,\r
902                       const char *subkey, const char *val);\r
903 void conf_del_str_str(Conf *conf, int key, const char *subkey);\r
904 void conf_set_filename(Conf *conf, int key, const Filename *val);\r
905 void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);\r
906 /* Serialisation functions for Duplicate Session */\r
907 int conf_serialised_size(Conf *conf);\r
908 void conf_serialise(Conf *conf, void *data);\r
909 int conf_deserialise(Conf *conf, void *data, int maxsize);/*returns size used*/\r
911 /*\r
912  * Functions to copy, free, serialise and deserialise FontSpecs.\r
913  * Provided per-platform, to go with the platform's idea of a\r
914  * FontSpec's contents.\r
915  *\r
916  * fontspec_serialise returns the number of bytes written, and can\r
917  * handle data==NULL without crashing. So you can call it once to find\r
918  * out a size, then again once you've allocated a buffer.\r
919  */\r
920 FontSpec *fontspec_copy(const FontSpec *f);\r
921 void fontspec_free(FontSpec *f);\r
922 int fontspec_serialise(FontSpec *f, void *data);\r
923 FontSpec *fontspec_deserialise(void *data, int maxsize, int *used);\r
925 /*\r
926  * Exports from noise.c.\r
927  */\r
928 void noise_get_heavy(void (*func) (void *, int));\r
929 void noise_get_light(void (*func) (void *, int));\r
930 void noise_regular(void);\r
931 void noise_ultralight(unsigned long data);\r
932 void random_save_seed(void);\r
933 void random_destroy_seed(void);\r
935 /*\r
936  * Exports from settings.c.\r
937  */\r
938 Backend *backend_from_name(const char *name);\r
939 Backend *backend_from_proto(int proto);\r
940 char *get_remote_username(Conf *conf); /* dynamically allocated */\r
941 char *save_settings(char *section, Conf *conf);\r
942 void save_open_settings(void *sesskey, Conf *conf);\r
943 void load_settings(char *section, Conf *conf);\r
944 void load_open_settings(void *sesskey, Conf *conf);\r
945 void get_sesslist(struct sesslist *, int allocate);\r
946 void do_defaults(char *, Conf *);\r
947 void registry_cleanup(void);\r
949 /*\r
950  * Functions used by settings.c to provide platform-specific\r
951  * default settings.\r
952  * \r
953  * (The integer one is expected to return `def' if it has no clear\r
954  * opinion of its own. This is because there's no integer value\r
955  * which I can reliably set aside to indicate `nil'. The string\r
956  * function is perfectly all right returning NULL, of course. The\r
957  * Filename and FontSpec functions are _not allowed_ to fail to\r
958  * return, since these defaults _must_ be per-platform.)\r
959  *\r
960  * The 'Filename *' returned by platform_default_filename, and the\r
961  * 'FontSpec *' returned by platform_default_fontspec, have ownership\r
962  * transferred to the caller, and must be freed.\r
963  */\r
964 char *platform_default_s(const char *name);\r
965 int platform_default_i(const char *name, int def);\r
966 Filename *platform_default_filename(const char *name);\r
967 FontSpec *platform_default_fontspec(const char *name);\r
969 /*\r
970  * Exports from terminal.c.\r
971  */\r
973 Terminal *term_init(Conf *, struct unicode_data *, void *);\r
974 void term_free(Terminal *);\r
975 void term_size(Terminal *, int, int, int);\r
976 void term_paint(Terminal *, Context, int, int, int, int, int);\r
977 void term_scroll(Terminal *, int, int);\r
978 void term_scroll_to_selection(Terminal *, int);\r
979 void term_pwron(Terminal *, int);\r
980 void term_clrsb(Terminal *);\r
981 void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,\r
982                 int,int,int,int,int);\r
983 void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,\r
984               unsigned int);\r
985 void term_deselect(Terminal *);\r
986 void term_update(Terminal *);\r
987 void term_invalidate(Terminal *);\r
988 void term_blink(Terminal *, int set_cursor);\r
989 void term_do_paste(Terminal *);\r
990 void term_nopaste(Terminal *);\r
991 int term_ldisc(Terminal *, int option);\r
992 void term_copyall(Terminal *);\r
993 void term_reconfig(Terminal *, Conf *);\r
994 void term_seen_key_event(Terminal *); \r
995 int term_data(Terminal *, int is_stderr, const char *data, int len);\r
996 int term_data_untrusted(Terminal *, const char *data, int len);\r
997 void term_provide_resize_fn(Terminal *term,\r
998                             void (*resize_fn)(void *, int, int),\r
999                             void *resize_ctx);\r
1000 void term_provide_logctx(Terminal *term, void *logctx);\r
1001 void term_set_focus(Terminal *term, int has_focus);\r
1002 char *term_get_ttymode(Terminal *term, const char *mode);\r
1003 int term_get_userpass_input(Terminal *term, prompts_t *p,\r
1004                             unsigned char *in, int inlen);\r
1006 int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);\r
1008 /*\r
1009  * Exports from logging.c.\r
1010  */\r
1011 void *log_init(void *frontend, Conf *conf);\r
1012 void log_free(void *logctx);\r
1013 void log_reconfig(void *logctx, Conf *conf);\r
1014 void logfopen(void *logctx);\r
1015 void logfclose(void *logctx);\r
1016 void logtraffic(void *logctx, unsigned char c, int logmode);\r
1017 void logflush(void *logctx);\r
1018 void log_eventlog(void *logctx, const char *string);\r
1019 enum { PKT_INCOMING, PKT_OUTGOING };\r
1020 enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };\r
1021 struct logblank_t {\r
1022     int offset;\r
1023     int len;\r
1024     int type;\r
1025 };\r
1026 void log_packet(void *logctx, int direction, int type,\r
1027                 char *texttype, const void *data, int len,\r
1028                 int n_blanks, const struct logblank_t *blanks,\r
1029                 const unsigned long *sequence,\r
1030                 unsigned downstream_id, const char *additional_log_text);\r
1032 /*\r
1033  * Exports from testback.c\r
1034  */\r
1036 extern Backend null_backend;\r
1037 extern Backend loop_backend;\r
1039 /*\r
1040  * Exports from raw.c.\r
1041  */\r
1043 extern Backend raw_backend;\r
1045 /*\r
1046  * Exports from rlogin.c.\r
1047  */\r
1049 extern Backend rlogin_backend;\r
1051 /*\r
1052  * Exports from telnet.c.\r
1053  */\r
1055 extern Backend telnet_backend;\r
1057 /*\r
1058  * Exports from ssh.c.\r
1059  */\r
1060 extern Backend ssh_backend;\r
1062 /*\r
1063  * Exports from ldisc.c.\r
1064  */\r
1065 void *ldisc_create(Conf *, Terminal *, Backend *, void *, void *);\r
1066 void ldisc_configure(void *, Conf *);\r
1067 void ldisc_free(void *);\r
1068 void ldisc_send(void *handle, char *buf, int len, int interactive);\r
1070 /*\r
1071  * Exports from ldiscucs.c.\r
1072  */\r
1073 void lpage_send(void *, int codepage, char *buf, int len, int interactive);\r
1074 void luni_send(void *, wchar_t * widebuf, int len, int interactive);\r
1076 /*\r
1077  * Exports from sshrand.c.\r
1078  */\r
1080 void random_add_noise(void *noise, int length);\r
1081 int random_byte(void);\r
1082 void random_get_savedata(void **data, int *len);\r
1083 extern int random_active;\r
1084 /* The random number subsystem is activated if at least one other entity\r
1085  * within the program expresses an interest in it. So each SSH session\r
1086  * calls random_ref on startup and random_unref on shutdown. */\r
1087 void random_ref(void);\r
1088 void random_unref(void);\r
1090 /*\r
1091  * Exports from pinger.c.\r
1092  */\r
1093 typedef struct pinger_tag *Pinger;\r
1094 Pinger pinger_new(Conf *conf, Backend *back, void *backhandle);\r
1095 void pinger_reconfig(Pinger, Conf *oldconf, Conf *newconf);\r
1096 void pinger_free(Pinger);\r
1098 /*\r
1099  * Exports from misc.c.\r
1100  */\r
1102 #include "misc.h"\r
1103 int conf_launchable(Conf *conf);\r
1104 char const *conf_dest(Conf *conf);\r
1106 /*\r
1107  * Exports from sercfg.c.\r
1108  */\r
1109 void ser_setup_config_box(struct controlbox *b, int midsession,\r
1110                           int parity_mask, int flow_mask);\r
1112 /*\r
1113  * Exports from version.c.\r
1114  */\r
1115 extern char ver[];\r
1117 /*\r
1118  * Exports from unicode.c.\r
1119  */\r
1120 #ifndef CP_UTF8\r
1121 #define CP_UTF8 65001\r
1122 #endif\r
1123 /* void init_ucs(void); -- this is now in platform-specific headers */\r
1124 int is_dbcs_leadbyte(int codepage, char byte);\r
1125 int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,\r
1126              wchar_t *wcstr, int wclen);\r
1127 int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,\r
1128              char *mbstr, int mblen, char *defchr, int *defused,\r
1129              struct unicode_data *ucsdata);\r
1130 wchar_t xlat_uskbd2cyrllic(int ch);\r
1131 int check_compose(int first, int second);\r
1132 int decode_codepage(char *cp_name);\r
1133 const char *cp_enumerate (int index);\r
1134 const char *cp_name(int codepage);\r
1135 void get_unitab(int codepage, wchar_t * unitab, int ftype);\r
1137 /*\r
1138  * Exports from wcwidth.c\r
1139  */\r
1140 int mk_wcwidth(unsigned int ucs);\r
1141 int mk_wcswidth(const unsigned int *pwcs, size_t n);\r
1142 int mk_wcwidth_cjk(unsigned int ucs);\r
1143 int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);\r
1145 /*\r
1146  * Exports from mscrypto.c\r
1147  */\r
1148 #ifdef MSCRYPTOAPI\r
1149 int crypto_startup();\r
1150 void crypto_wrapup();\r
1151 #endif\r
1153 /*\r
1154  * Exports from pageantc.c.\r
1155  * \r
1156  * agent_query returns 1 for here's-a-response, and 0 for query-in-\r
1157  * progress. In the latter case there will be a call to `callback'\r
1158  * at some future point, passing callback_ctx as the first\r
1159  * parameter and the actual reply data as the second and third.\r
1160  * \r
1161  * The response may be a NULL pointer (in either of the synchronous\r
1162  * or asynchronous cases), which indicates failure to receive a\r
1163  * response.\r
1164  */\r
1165 int agent_query(void *in, int inlen, void **out, int *outlen,\r
1166                 void (*callback)(void *, void *, int), void *callback_ctx);\r
1167 int agent_exists(void);\r
1169 /*\r
1170  * Exports from wildcard.c\r
1171  */\r
1172 const char *wc_error(int value);\r
1173 int wc_match(const char *wildcard, const char *target);\r
1174 int wc_unescape(char *output, const char *wildcard);\r
1176 /*\r
1177  * Exports from frontend (windlg.c etc)\r
1178  */\r
1179 void logevent(void *frontend, const char *);\r
1180 void pgp_fingerprints(void);\r
1181 /*\r
1182  * verify_ssh_host_key() can return one of three values:\r
1183  * \r
1184  *  - +1 means `key was OK' (either already known or the user just\r
1185  *    approved it) `so continue with the connection'\r
1186  * \r
1187  *  - 0 means `key was not OK, abandon the connection'\r
1188  * \r
1189  *  - -1 means `I've initiated enquiries, please wait to be called\r
1190  *    back via the provided function with a result that's either 0\r
1191  *    or +1'.\r
1192  */\r
1193 int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,\r
1194                         char *keystr, char *fingerprint,\r
1195                         void (*callback)(void *ctx, int result), void *ctx);\r
1196 /*\r
1197  * askalg has the same set of return values as verify_ssh_host_key.\r
1198  */\r
1199 int askalg(void *frontend, const char *algtype, const char *algname,\r
1200            void (*callback)(void *ctx, int result), void *ctx);\r
1201 /*\r
1202  * askappend can return four values:\r
1203  * \r
1204  *  - 2 means overwrite the log file\r
1205  *  - 1 means append to the log file\r
1206  *  - 0 means cancel logging for this session\r
1207  *  - -1 means please wait.\r
1208  */\r
1209 int askappend(void *frontend, Filename *filename,\r
1210               void (*callback)(void *ctx, int result), void *ctx);\r
1212 /*\r
1213  * Exports from console frontends (wincons.c, uxcons.c)\r
1214  * that aren't equivalents to things in windlg.c et al.\r
1215  */\r
1216 extern int console_batch_mode;\r
1217 int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen);\r
1218 void console_provide_logctx(void *logctx);\r
1219 int is_interactive(void);\r
1221 /*\r
1222  * Exports from printing.c.\r
1223  */\r
1224 typedef struct printer_enum_tag printer_enum;\r
1225 typedef struct printer_job_tag printer_job;\r
1226 printer_enum *printer_start_enum(int *nprinters);\r
1227 char *printer_get_name(printer_enum *, int);\r
1228 void printer_finish_enum(printer_enum *);\r
1229 printer_job *printer_start_job(char *printer);\r
1230 void printer_job_data(printer_job *, void *, int);\r
1231 void printer_finish_job(printer_job *);\r
1233 /*\r
1234  * Exports from cmdline.c (and also cmdline_error(), which is\r
1235  * defined differently in various places and required _by_\r
1236  * cmdline.c).\r
1237  */\r
1238 int cmdline_process_param(char *, char *, int, Conf *);\r
1239 void cmdline_run_saved(Conf *);\r
1240 void cmdline_cleanup(void);\r
1241 int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen);\r
1242 #define TOOLTYPE_FILETRANSFER 1\r
1243 #define TOOLTYPE_NONNETWORK 2\r
1244 extern int cmdline_tooltype;\r
1246 void cmdline_error(char *, ...);\r
1248 /*\r
1249  * Exports from config.c.\r
1250  */\r
1251 struct controlbox;\r
1252 union control;\r
1253 void conf_radiobutton_handler(union control *ctrl, void *dlg,\r
1254                               void *data, int event);\r
1255 #define CHECKBOX_INVERT (1<<30)\r
1256 void conf_checkbox_handler(union control *ctrl, void *dlg,\r
1257                            void *data, int event);\r
1258 void conf_editbox_handler(union control *ctrl, void *dlg,\r
1259                           void *data, int event);\r
1260 void conf_filesel_handler(union control *ctrl, void *dlg,\r
1261                           void *data, int event);\r
1262 void conf_fontsel_handler(union control *ctrl, void *dlg,\r
1263                           void *data, int event);\r
1264 void setup_config_box(struct controlbox *b, int midsession,\r
1265                       int protocol, int protcfginfo);\r
1267 /*\r
1268  * Exports from minibidi.c.\r
1269  */\r
1270 typedef struct bidi_char {\r
1271     unsigned int origwc, wc;\r
1272     unsigned short index;\r
1273 } bidi_char;\r
1274 int do_bidi(bidi_char *line, int count);\r
1275 int do_shape(bidi_char *line, bidi_char *to, int count);\r
1276 int is_rtl(int c);\r
1278 /*\r
1279  * X11 auth mechanisms we know about.\r
1280  */\r
1281 enum {\r
1282     X11_NO_AUTH,\r
1283     X11_MIT,                           /* MIT-MAGIC-COOKIE-1 */\r
1284     X11_XDM,                           /* XDM-AUTHORIZATION-1 */\r
1285     X11_NAUTHS\r
1286 };\r
1287 extern const char *const x11_authnames[];  /* declared in x11fwd.c */\r
1289 /*\r
1290  * Miscellaneous exports from the platform-specific code.\r
1291  *\r
1292  * filename_serialise and filename_deserialise have the same semantics\r
1293  * as fontspec_serialise and fontspec_deserialise above.\r
1294  */\r
1295 Filename *filename_from_str(const char *string);\r
1296 const char *filename_to_str(const Filename *fn);\r
1297 int filename_equal(const Filename *f1, const Filename *f2);\r
1298 int filename_is_null(const Filename *fn);\r
1299 Filename *filename_copy(const Filename *fn);\r
1300 void filename_free(Filename *fn);\r
1301 int filename_serialise(const Filename *f, void *data);\r
1302 Filename *filename_deserialise(void *data, int maxsize, int *used);\r
1303 char *get_username(void);              /* return value needs freeing */\r
1304 char *get_random_data(int bytes);      /* used in cmdgen.c */\r
1306 /*\r
1307  * Exports and imports from timing.c.\r
1308  *\r
1309  * schedule_timer() asks the front end to schedule a callback to a\r
1310  * timer function in a given number of ticks. The returned value is\r
1311  * the time (in ticks since an arbitrary offset) at which the\r
1312  * callback can be expected. This value will also be passed as the\r
1313  * `now' parameter to the callback function. Hence, you can (for\r
1314  * example) schedule an event at a particular time by calling\r
1315  * schedule_timer() and storing the return value in your context\r
1316  * structure as the time when that event is due. The first time a\r
1317  * callback function gives you that value or more as `now', you do\r
1318  * the thing.\r
1319  * \r
1320  * expire_timer_context() drops all current timers associated with\r
1321  * a given value of ctx (for when you're about to free ctx).\r
1322  * \r
1323  * run_timers() is called from the front end when it has reason to\r
1324  * think some timers have reached their moment, or when it simply\r
1325  * needs to know how long to wait next. We pass it the time we\r
1326  * think it is. It returns TRUE and places the time when the next\r
1327  * timer needs to go off in `next', or alternatively it returns\r
1328  * FALSE if there are no timers at all pending.\r
1329  * \r
1330  * timer_change_notify() must be supplied by the front end; it\r
1331  * notifies the front end that a new timer has been added to the\r
1332  * list which is sooner than any existing ones. It provides the\r
1333  * time when that timer needs to go off.\r
1334  * \r
1335  * *** FRONT END IMPLEMENTORS NOTE:\r
1336  * \r
1337  * There's an important subtlety in the front-end implementation of\r
1338  * the timer interface. When a front end is given a `next' value,\r
1339  * either returned from run_timers() or via timer_change_notify(),\r
1340  * it should ensure that it really passes _that value_ as the `now'\r
1341  * parameter to its next run_timers call. It should _not_ simply\r
1342  * call GETTICKCOUNT() to get the `now' parameter when invoking\r
1343  * run_timers().\r
1344  * \r
1345  * The reason for this is that an OS's system clock might not agree\r
1346  * exactly with the timing mechanisms it supplies to wait for a\r
1347  * given interval. I'll illustrate this by the simple example of\r
1348  * Unix Plink, which uses timeouts to select() in a way which for\r
1349  * these purposes can simply be considered to be a wait() function.\r
1350  * Suppose, for the sake of argument, that this wait() function\r
1351  * tends to return early by 1%. Then a possible sequence of actions\r
1352  * is:\r
1353  * \r
1354  *  - run_timers() tells the front end that the next timer firing\r
1355  *    is 10000ms from now.\r
1356  *  - Front end calls wait(10000ms), but according to\r
1357  *    GETTICKCOUNT() it has only waited for 9900ms.\r
1358  *  - Front end calls run_timers() again, passing time T-100ms as\r
1359  *    `now'.\r
1360  *  - run_timers() does nothing, and says the next timer firing is\r
1361  *    still 100ms from now.\r
1362  *  - Front end calls wait(100ms), which only waits for 99ms.\r
1363  *  - Front end calls run_timers() yet again, passing time T-1ms.\r
1364  *  - run_timers() says there's still 1ms to wait.\r
1365  *  - Front end calls wait(1ms).\r
1366  * \r
1367  * If you're _lucky_ at this point, wait(1ms) will actually wait\r
1368  * for 1ms and you'll only have woken the program up three times.\r
1369  * If you're unlucky, wait(1ms) might do nothing at all due to\r
1370  * being below some minimum threshold, and you might find your\r
1371  * program spends the whole of the last millisecond tight-looping\r
1372  * between wait() and run_timers().\r
1373  * \r
1374  * Instead, what you should do is to _save_ the precise `next'\r
1375  * value provided by run_timers() or via timer_change_notify(), and\r
1376  * use that precise value as the input to the next run_timers()\r
1377  * call. So:\r
1378  * \r
1379  *  - run_timers() tells the front end that the next timer firing\r
1380  *    is at time T, 10000ms from now.\r
1381  *  - Front end calls wait(10000ms).\r
1382  *  - Front end then immediately calls run_timers() and passes it\r
1383  *    time T, without stopping to check GETTICKCOUNT() at all.\r
1384  * \r
1385  * This guarantees that the program wakes up only as many times as\r
1386  * there are actual timer actions to be taken, and that the timing\r
1387  * mechanism will never send it into a tight loop.\r
1388  * \r
1389  * (It does also mean that the timer action in the above example\r
1390  * will occur 100ms early, but this is not generally critical. And\r
1391  * the hypothetical 1% error in wait() will be partially corrected\r
1392  * for anyway when, _after_ run_timers() returns, you call\r
1393  * GETTICKCOUNT() and compare the result with the returned `next'\r
1394  * value to find out how long you have to make your next wait().)\r
1395  */\r
1396 typedef void (*timer_fn_t)(void *ctx, unsigned long now);\r
1397 unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);\r
1398 void expire_timer_context(void *ctx);\r
1399 int run_timers(unsigned long now, unsigned long *next);\r
1400 void timer_change_notify(unsigned long next);\r
1402 /*\r
1403  * Exports from callback.c.\r
1404  *\r
1405  * This provides a method of queuing function calls to be run at the\r
1406  * earliest convenience from the top-level event loop. Use it if\r
1407  * you're deep in a nested chain of calls and want to trigger an\r
1408  * action which will probably lead to your function being re-entered\r
1409  * recursively if you just call the initiating function the normal\r
1410  * way.\r
1411  *\r
1412  * Most front ends run the queued callbacks by simply calling\r
1413  * run_toplevel_callbacks() after handling each event in their\r
1414  * top-level event loop. However, if a front end doesn't have control\r
1415  * over its own event loop (e.g. because it's using GTK) then it can\r
1416  * instead request notifications when a callback is available, so that\r
1417  * it knows to ask its delegate event loop to do the same thing. Also,\r
1418  * if a front end needs to know whether a callback is pending without\r
1419  * actually running it (e.g. so as to put a zero timeout on a select()\r
1420  * call) then it can call toplevel_callback_pending(), which will\r
1421  * return true if at least one callback is in the queue.\r
1422  */\r
1423 typedef void (*toplevel_callback_fn_t)(void *ctx);\r
1424 void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);\r
1425 void run_toplevel_callbacks(void);\r
1426 int toplevel_callback_pending(void);\r
1428 typedef void (*toplevel_callback_notify_fn_t)(void *frontend);\r
1429 void request_callback_notifications(toplevel_callback_notify_fn_t notify,\r
1430                                     void *frontend);\r
1432 /*\r
1433  * Define no-op macros for the jump list functions, on platforms that\r
1434  * don't support them. (This is a bit of a hack, and it'd be nicer to\r
1435  * localise even the calls to those functions into the Windows front\r
1436  * end, but it'll do for the moment.)\r
1437  */\r
1438 #ifndef JUMPLIST_SUPPORTED\r
1439 #define add_session_to_jumplist(x) ((void)0)\r
1440 #define remove_session_from_jumplist(x) ((void)0)\r
1441 #endif\r
1443 /* SURROGATE PAIR */\r
1444 #define HIGH_SURROGATE_START 0xd800\r
1445 #define HIGH_SURROGATE_END 0xdbff\r
1446 #define LOW_SURROGATE_START 0xdc00\r
1447 #define LOW_SURROGATE_END 0xdfff\r
1449 /* These macros exist in the Windows API, so the environment may\r
1450  * provide them. If not, define them in terms of the above. */\r
1451 #ifndef IS_HIGH_SURROGATE\r
1452 #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \\r
1453                                 ((wch) <= HIGH_SURROGATE_END))\r
1454 #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \\r
1455                                ((wch) <= LOW_SURROGATE_END))\r
1456 #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \\r
1457                                    IS_LOW_SURROGATE(ls))\r
1458 #endif\r
1461 #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) &&   \\r
1462                            ((wch) <= LOW_SURROGATE_END))\r
1463 #define HIGH_SURROGATE_OF(codept) \\r
1464     (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))\r
1465 #define LOW_SURROGATE_OF(codept) \\r
1466     (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))\r
1467 #define FROM_SURROGATES(wch1, wch2) \\r
1468     (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))\r
1470 #endif\r