putty.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. #ifndef PUTTY_PUTTY_H
  2. #define PUTTY_PUTTY_H
  3. #include <stddef.h> /* for wchar_t */
  4. /*
  5. * Global variables. Most modules declare these `extern', but
  6. * window.c will do `#define PUTTY_DO_GLOBALS' before including this
  7. * module, and so will get them properly defined.
  8. */
  9. #ifndef GLOBAL
  10. #ifdef PUTTY_DO_GLOBALS
  11. #define GLOBAL
  12. #else
  13. #define GLOBAL extern
  14. #endif
  15. #endif
  16. #ifndef DONE_TYPEDEFS
  17. #define DONE_TYPEDEFS
  18. typedef struct config_tag Config;
  19. typedef struct backend_tag Backend;
  20. typedef struct terminal_tag Terminal;
  21. #endif
  22. #include "puttyps.h"
  23. #include "network.h"
  24. #include "misc.h"
  25. /*
  26. * Fingerprints of the PGP master keys that can be used to establish a trust
  27. * path between an executable and other files.
  28. */
  29. #define PGP_RSA_MASTER_KEY_FP \
  30. "8F 15 97 DA 25 30 AB 0D 88 D1 92 54 11 CF 0C 4C"
  31. #define PGP_DSA_MASTER_KEY_FP \
  32. "313C 3E76 4B74 C2C5 F2AE 83A8 4F5E 6DF5 6A93 B34E"
  33. /* Three attribute types:
  34. * The ATTRs (normal attributes) are stored with the characters in
  35. * the main display arrays
  36. *
  37. * The TATTRs (temporary attributes) are generated on the fly, they
  38. * can overlap with characters but not with normal attributes.
  39. *
  40. * The LATTRs (line attributes) are an entirely disjoint space of
  41. * flags.
  42. *
  43. * The DATTRs (display attributes) are internal to terminal.c (but
  44. * defined here because their values have to match the others
  45. * here); they reuse the TATTR_* space but are always masked off
  46. * before sending to the front end.
  47. *
  48. * ATTR_INVALID is an illegal colour combination.
  49. */
  50. #define TATTR_ACTCURS 0x40000000UL /* active cursor (block) */
  51. #define TATTR_PASCURS 0x20000000UL /* passive cursor (box) */
  52. #define TATTR_RIGHTCURS 0x10000000UL /* cursor-on-RHS */
  53. #define TATTR_COMBINING 0x80000000UL /* combining characters */
  54. #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */
  55. #define TDATTR_MASK 0xF0000000UL
  56. #define TATTR_MASK (TDATTR_MASK)
  57. #define DATTR_MASK (TDATTR_MASK)
  58. #define LATTR_NORM 0x00000000UL
  59. #define LATTR_WIDE 0x00000001UL
  60. #define LATTR_TOP 0x00000002UL
  61. #define LATTR_BOT 0x00000003UL
  62. #define LATTR_MODE 0x00000003UL
  63. #define LATTR_WRAPPED 0x00000010UL /* this line wraps to next */
  64. #define LATTR_WRAPPED2 0x00000020UL /* with WRAPPED: CJK wide character
  65. wrapped to next line, so last
  66. single-width cell is empty */
  67. #define ATTR_INVALID 0x03FFFFU
  68. /* Like Linux use the F000 page for direct to font. */
  69. #define CSET_OEMCP 0x0000F000UL /* OEM Codepage DTF */
  70. #define CSET_ACP 0x0000F100UL /* Ansi Codepage DTF */
  71. /* These are internal use overlapping with the UTF-16 surrogates */
  72. #define CSET_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
  73. #define CSET_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
  74. #define CSET_SCOACS 0x0000DA00UL /* SCO Alternate charset */
  75. #define CSET_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
  76. #define CSET_MASK 0xFFFFFF00UL /* Character set mask */
  77. #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
  78. #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xF000)
  79. #define UCSERR (CSET_LINEDRW|'a') /* UCS Format error character. */
  80. /*
  81. * UCSWIDE is a special value used in the terminal data to signify
  82. * the character cell containing the right-hand half of a CJK wide
  83. * character. We use 0xDFFF because it's part of the surrogate
  84. * range and hence won't be used for anything else (it's impossible
  85. * to input it via UTF-8 because our UTF-8 decoder correctly
  86. * rejects surrogates).
  87. */
  88. #define UCSWIDE 0xDFFF
  89. #define ATTR_NARROW 0x800000U
  90. #define ATTR_WIDE 0x400000U
  91. #define ATTR_BOLD 0x040000U
  92. #define ATTR_UNDER 0x080000U
  93. #define ATTR_REVERSE 0x100000U
  94. #define ATTR_BLINK 0x200000U
  95. #define ATTR_FGMASK 0x0001FFU
  96. #define ATTR_BGMASK 0x03FE00U
  97. #define ATTR_COLOURS 0x03FFFFU
  98. #define ATTR_FGSHIFT 0
  99. #define ATTR_BGSHIFT 9
  100. /*
  101. * The definitive list of colour numbers stored in terminal
  102. * attribute words is kept here. It is:
  103. *
  104. * - 0-7 are ANSI colours (KRGYBMCW).
  105. * - 8-15 are the bold versions of those colours.
  106. * - 16-255 are the remains of the xterm 256-colour mode (a
  107. * 216-colour cube with R at most significant and B at least,
  108. * followed by a uniform series of grey shades running between
  109. * black and white but not including either on grounds of
  110. * redundancy).
  111. * - 256 is default foreground
  112. * - 257 is default bold foreground
  113. * - 258 is default background
  114. * - 259 is default bold background
  115. * - 260 is cursor foreground
  116. * - 261 is cursor background
  117. */
  118. #define ATTR_DEFFG (256 << ATTR_FGSHIFT)
  119. #define ATTR_DEFBG (258 << ATTR_BGSHIFT)
  120. #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
  121. struct sesslist {
  122. int nsessions;
  123. char **sessions;
  124. char *buffer; /* so memory can be freed later */
  125. };
  126. struct unicode_data {
  127. char **uni_tbl;
  128. int dbcs_screenfont;
  129. int font_codepage;
  130. int line_codepage;
  131. wchar_t unitab_scoacs[256];
  132. wchar_t unitab_line[256];
  133. wchar_t unitab_font[256];
  134. wchar_t unitab_xterm[256];
  135. wchar_t unitab_oemcp[256];
  136. unsigned char unitab_ctrl[256];
  137. };
  138. #define LGXF_OVR 1 /* existing logfile overwrite */
  139. #define LGXF_APN 0 /* existing logfile append */
  140. #define LGXF_ASK -1 /* existing logfile ask */
  141. #define LGTYP_NONE 0 /* logmode: no logging */
  142. #define LGTYP_ASCII 1 /* logmode: pure ascii */
  143. #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
  144. #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
  145. #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */
  146. typedef enum {
  147. /* Actual special commands. Originally Telnet, but some codes have
  148. * been re-used for similar specials in other protocols. */
  149. TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
  150. TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF, TS_LECHO, TS_RECHO, TS_PING,
  151. TS_EOL,
  152. /* Special command for SSH. */
  153. TS_REKEY,
  154. /* POSIX-style signals. (not Telnet) */
  155. TS_SIGABRT, TS_SIGALRM, TS_SIGFPE, TS_SIGHUP, TS_SIGILL,
  156. TS_SIGINT, TS_SIGKILL, TS_SIGPIPE, TS_SIGQUIT, TS_SIGSEGV,
  157. TS_SIGTERM, TS_SIGUSR1, TS_SIGUSR2,
  158. /* Pseudo-specials used for constructing the specials menu. */
  159. TS_SEP, /* Separator */
  160. TS_SUBMENU, /* Start a new submenu with specified name */
  161. TS_EXITMENU /* Exit current submenu or end of specials */
  162. } Telnet_Special;
  163. struct telnet_special {
  164. const char *name;
  165. int code;
  166. };
  167. typedef enum {
  168. MBT_NOTHING,
  169. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  170. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  171. MBT_WHEEL_UP, MBT_WHEEL_DOWN /* mouse wheel */
  172. } Mouse_Button;
  173. typedef enum {
  174. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
  175. } Mouse_Action;
  176. /* Keyboard modifiers -- keys the user is actually holding down */
  177. #define PKM_SHIFT 0x01
  178. #define PKM_CONTROL 0x02
  179. #define PKM_META 0x04
  180. #define PKM_ALT 0x08
  181. /* Keyboard flags that aren't really modifiers */
  182. #define PKF_CAPSLOCK 0x10
  183. #define PKF_NUMLOCK 0x20
  184. #define PKF_REPEAT 0x40
  185. /* Stand-alone keysyms for function keys */
  186. typedef enum {
  187. PK_NULL, /* No symbol for this key */
  188. /* Main keypad keys */
  189. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  190. /* Editing keys */
  191. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  192. /* Cursor keys */
  193. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  194. /* Numeric keypad */ /* Real one looks like: */
  195. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  196. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  197. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  198. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  199. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  200. /* Top row */
  201. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  202. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  203. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  204. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  205. PK_PAUSE
  206. } Key_Sym;
  207. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  208. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  209. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  210. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  211. enum {
  212. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  213. };
  214. enum {
  215. /*
  216. * SSH-2 key exchange algorithms
  217. */
  218. KEX_WARN,
  219. KEX_DHGROUP1,
  220. KEX_DHGROUP14,
  221. KEX_DHGEX,
  222. #ifdef SSPI_MECH
  223. KEX_GSSGROUP1,
  224. KEX_GSSGROUP14,
  225. KEX_GSSGEX,
  226. #endif
  227. KEX_MAX
  228. };
  229. enum {
  230. /*
  231. * SSH ciphers (both SSH-1 and SSH-2)
  232. */
  233. CIPHER_WARN, /* pseudo 'cipher' */
  234. CIPHER_3DES,
  235. CIPHER_BLOWFISH,
  236. CIPHER_AES, /* (SSH-2 only) */
  237. CIPHER_DES,
  238. CIPHER_ARCFOUR,
  239. CIPHER_MAX /* no. ciphers (inc warn) */
  240. };
  241. enum {
  242. /*
  243. * Several different bits of the PuTTY configuration seem to be
  244. * three-way settings whose values are `always yes', `always
  245. * no', and `decide by some more complex automated means'. This
  246. * is true of line discipline options (local echo and line
  247. * editing), proxy DNS, Close On Exit, and SSH server bug
  248. * workarounds. Accordingly I supply a single enum here to deal
  249. * with them all.
  250. */
  251. FORCE_ON, FORCE_OFF, AUTO
  252. };
  253. enum {
  254. /*
  255. * Proxy types.
  256. */
  257. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  258. PROXY_HTTP, PROXY_TELNET, PROXY_CMD
  259. };
  260. enum {
  261. /*
  262. * Line discipline options which the backend might try to control.
  263. */
  264. LD_EDIT, /* local line editing */
  265. LD_ECHO /* local echo */
  266. };
  267. enum {
  268. /* Actions on remote window title query */
  269. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  270. };
  271. enum {
  272. /* Protocol back ends. (cfg.protocol) */
  273. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
  274. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  275. * hurt to define it globally. */
  276. PROT_SERIAL
  277. };
  278. enum {
  279. /* Bell settings (cfg.beep) */
  280. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  281. };
  282. enum {
  283. /* Taskbar flashing indication on bell (cfg.beep_ind) */
  284. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  285. };
  286. enum {
  287. /* Resize actions (cfg.resize_action) */
  288. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  289. };
  290. enum {
  291. /* Function key types (cfg.funky_type) */
  292. FUNKY_TILDE,
  293. FUNKY_LINUX,
  294. FUNKY_XTERM,
  295. FUNKY_VT400,
  296. FUNKY_VT100P,
  297. FUNKY_SCO
  298. };
  299. enum {
  300. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  301. };
  302. enum {
  303. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  304. };
  305. enum {
  306. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  307. };
  308. extern const char *const ttymodes[];
  309. enum {
  310. /*
  311. * Network address types. Used for specifying choice of IPv4/v6
  312. * in config; also used in proxy.c to indicate whether a given
  313. * host name has already been resolved or will be resolved at
  314. * the proxy end.
  315. */
  316. ADDRTYPE_UNSPEC, ADDRTYPE_IPV4, ADDRTYPE_IPV6, ADDRTYPE_NAME
  317. };
  318. struct backend_tag {
  319. const char *(*init) (void *frontend_handle, void **backend_handle,
  320. Config *cfg,
  321. char *host, int port, char **realhost, int nodelay,
  322. int keepalive);
  323. void (*free) (void *handle);
  324. /* back->reconfig() passes in a replacement configuration. */
  325. void (*reconfig) (void *handle, Config *cfg);
  326. /* back->send() returns the current amount of buffered data. */
  327. int (*send) (void *handle, char *buf, int len);
  328. /* back->sendbuffer() does the same thing but without attempting a send */
  329. int (*sendbuffer) (void *handle);
  330. void (*size) (void *handle, int width, int height);
  331. void (*special) (void *handle, Telnet_Special code);
  332. const struct telnet_special *(*get_specials) (void *handle);
  333. int (*connected) (void *handle);
  334. int (*exitcode) (void *handle);
  335. /* If back->sendok() returns FALSE, data sent to it from the frontend
  336. * may be lost. */
  337. int (*sendok) (void *handle);
  338. int (*ldisc) (void *handle, int);
  339. void (*provide_ldisc) (void *handle, void *ldisc);
  340. void (*provide_logctx) (void *handle, void *logctx);
  341. /*
  342. * back->unthrottle() tells the back end that the front end
  343. * buffer is clearing.
  344. */
  345. void (*unthrottle) (void *handle, int);
  346. int (*cfg_info) (void *handle);
  347. int default_port;
  348. };
  349. extern struct backend_list {
  350. int protocol;
  351. char *name;
  352. Backend *backend;
  353. } backends[];
  354. /*
  355. * Suggested default protocol provided by the backend link module.
  356. * The application is free to ignore this.
  357. */
  358. extern const int be_default_protocol;
  359. /*
  360. * Name of this particular application, for use in the config box
  361. * and other pieces of text.
  362. */
  363. extern const char *const appname;
  364. /*
  365. * IMPORTANT POLICY POINT: everything in this structure which wants
  366. * to be treated like an integer must be an actual, honest-to-
  367. * goodness `int'. No enum-typed variables. This is because parts
  368. * of the code will want to pass around `int *' pointers to them
  369. * and we can't run the risk of porting to some system on which the
  370. * enum comes out as a different size from int.
  371. */
  372. struct config_tag {
  373. /* Basic options */
  374. char host[512];
  375. int port;
  376. int protocol;
  377. int addressfamily;
  378. int close_on_exit;
  379. int warn_on_close;
  380. int ping_interval; /* in seconds */
  381. int tcp_nodelay;
  382. int tcp_keepalives;
  383. /* Proxy options */
  384. char proxy_exclude_list[512];
  385. int proxy_dns;
  386. int even_proxy_localhost;
  387. int proxy_type;
  388. char proxy_host[512];
  389. int proxy_port;
  390. char proxy_username[128];
  391. char proxy_password[128];
  392. char proxy_telnet_command[512];
  393. /* SSH options */
  394. char remote_cmd[512];
  395. char *remote_cmd_ptr; /* might point to a larger command
  396. * but never for loading/saving */
  397. char *remote_cmd_ptr2; /* might point to a larger command
  398. * but never for loading/saving */
  399. int nopty;
  400. int compression;
  401. int ssh_kexlist[KEX_MAX];
  402. int ssh_rekey_time; /* in minutes */
  403. char ssh_rekey_data[16];
  404. int tryagent;
  405. int agentfwd;
  406. int change_username; /* allow username switching in SSH-2 */
  407. int ssh_cipherlist[CIPHER_MAX];
  408. Filename keyfile;
  409. int sshprot; /* use v1 or v2 when both available */
  410. int ssh2_des_cbc; /* "des-cbc" unrecommended SSH-2 cipher */
  411. int ssh_no_userauth; /* bypass "ssh-userauth" (SSH-2 only) */
  412. int try_tis_auth;
  413. int try_ki_auth;
  414. #ifdef SSPI_MECH
  415. int try_sspi_auth; /* try sspi on this connection? */
  416. int try_gsskex; /* try GSSKEX on this connection? */
  417. int sspi_fwd_ticket; /* should we flag the ticket as forwardable? */
  418. char service_principal_name[512]; /* the service principal name to use instead of the host name */
  419. int username_from_env; /* override username[] */
  420. int sspi_no_username; /* server will deduce username */
  421. int sspi_trust_dns; /* use DNS to make FQDNs out of short names */
  422. #endif
  423. int ssh_subsys; /* run a subsystem rather than a command */
  424. int ssh_subsys2; /* fallback to go with remote_cmd_ptr2 */
  425. int ssh_no_shell; /* avoid running a shell */
  426. char ssh_nc_host[512]; /* host to connect to in `nc' mode */
  427. int ssh_nc_port; /* port to connect to in `nc' mode */
  428. /* Telnet options */
  429. char termtype[32];
  430. char termspeed[32];
  431. char ttymodes[768]; /* MODE\tVvalue\0MODE\tA\0\0 */
  432. char environmt[1024]; /* VAR\tvalue\0VAR\tvalue\0\0 */
  433. char username[100];
  434. char localusername[100];
  435. int rfc_environ;
  436. int passive_telnet;
  437. /* Serial port options */
  438. char serline[256];
  439. int serspeed;
  440. int serdatabits, serstopbits;
  441. int serparity;
  442. int serflow;
  443. /* Keyboard options */
  444. int bksp_is_delete;
  445. int rxvt_homeend;
  446. int funky_type;
  447. int no_applic_c; /* totally disable app cursor keys */
  448. int no_applic_k; /* totally disable app keypad */
  449. int no_mouse_rep; /* totally disable mouse reporting */
  450. int no_remote_resize; /* disable remote resizing */
  451. int no_alt_screen; /* disable alternate screen */
  452. int no_remote_wintitle; /* disable remote retitling */
  453. int no_dbackspace; /* disable destructive backspace */
  454. int no_remote_charset; /* disable remote charset config */
  455. int remote_qtitle_action; /* remote win title query action */
  456. int app_cursor;
  457. int app_keypad;
  458. int nethack_keypad;
  459. int telnet_keyboard;
  460. int telnet_newline;
  461. int alt_f4; /* is it special? */
  462. int alt_space; /* is it special? */
  463. int alt_only; /* is it special? */
  464. int localecho;
  465. int localedit;
  466. int alwaysontop;
  467. int fullscreenonaltenter;
  468. int scroll_on_key;
  469. int scroll_on_disp;
  470. int erase_to_scrollback;
  471. int compose_key;
  472. int ctrlaltkeys;
  473. char wintitle[256]; /* initial window title */
  474. /* Terminal options */
  475. int savelines;
  476. int dec_om;
  477. int wrap_mode;
  478. int lfhascr;
  479. int cursor_type; /* 0=block 1=underline 2=vertical */
  480. int blink_cur;
  481. int beep;
  482. int beep_ind;
  483. int bellovl; /* bell overload protection active? */
  484. int bellovl_n; /* number of bells to cause overload */
  485. int bellovl_t; /* time interval for overload (seconds) */
  486. int bellovl_s; /* period of silence to re-enable bell (s) */
  487. Filename bell_wavefile;
  488. int scrollbar;
  489. int scrollbar_in_fullscreen;
  490. int resize_action;
  491. int bce;
  492. int blinktext;
  493. int win_name_always;
  494. int width, height;
  495. FontSpec font;
  496. int font_quality;
  497. Filename logfilename;
  498. int logtype;
  499. int logxfovr;
  500. int logflush;
  501. int logomitpass;
  502. int logomitdata;
  503. int hide_mouseptr;
  504. int sunken_edge;
  505. int window_border;
  506. char answerback[256];
  507. char printer[128];
  508. int arabicshaping;
  509. int bidi;
  510. /* Colour options */
  511. int ansi_colour;
  512. int xterm_256_colour;
  513. int system_colour;
  514. int try_palette;
  515. int bold_colour;
  516. unsigned char colours[22][3];
  517. /* Selection options */
  518. int mouse_is_xterm;
  519. int rect_select;
  520. int rawcnp;
  521. int rtf_paste;
  522. int mouse_override;
  523. short wordness[256];
  524. /* translations */
  525. int vtmode;
  526. char line_codepage[128];
  527. int cjk_ambig_wide;
  528. int utf8_override;
  529. int xlat_capslockcyr;
  530. /* X11 forwarding */
  531. int x11_forward;
  532. char x11_display[128];
  533. int x11_auth;
  534. /* port forwarding */
  535. int lport_acceptall; /* accept conns from hosts other than localhost */
  536. int rport_acceptall; /* same for remote forwarded ports (SSH-2 only) */
  537. /*
  538. * The port forwarding string contains a number of
  539. * NUL-terminated substrings, terminated in turn by an empty
  540. * string (i.e. a second NUL immediately after the previous
  541. * one). Each string can be of one of the following forms:
  542. *
  543. * [LR]localport\thost:port
  544. * [LR]localaddr:localport\thost:port
  545. * Dlocalport
  546. * Dlocaladdr:localport
  547. */
  548. char portfwd[1024];
  549. /* SSH bug compatibility modes */
  550. int sshbug_ignore1, sshbug_plainpw1, sshbug_rsa1,
  551. sshbug_hmac2, sshbug_derivekey2, sshbug_rsapad2,
  552. sshbug_pksessid2, sshbug_rekey2;
  553. /* Options for pterm. Should split out into platform-dependent part. */
  554. int stamp_utmp;
  555. int login_shell;
  556. int scrollbar_on_left;
  557. int shadowbold;
  558. FontSpec boldfont;
  559. FontSpec widefont;
  560. FontSpec wideboldfont;
  561. int shadowboldoffset;
  562. };
  563. /*
  564. * Some global flags denoting the type of application.
  565. *
  566. * FLAG_VERBOSE is set when the user requests verbose details.
  567. *
  568. * FLAG_STDERR is set in command-line applications (which have a
  569. * functioning stderr that it makes sense to write to) and not in
  570. * GUI applications (which don't).
  571. *
  572. * FLAG_INTERACTIVE is set when a full interactive shell session is
  573. * being run, _either_ because no remote command has been provided
  574. * _or_ because the application is GUI and can't run non-
  575. * interactively.
  576. *
  577. * These flags describe the type of _application_ - they wouldn't
  578. * vary between individual sessions - and so it's OK to have this
  579. * variable be GLOBAL.
  580. *
  581. * Note that additional flags may be defined in platform-specific
  582. * headers. It's probably best if those ones start from 0x1000, to
  583. * avoid collision.
  584. */
  585. #define FLAG_VERBOSE 0x0001
  586. #define FLAG_STDERR 0x0002
  587. #define FLAG_INTERACTIVE 0x0004
  588. GLOBAL int flags;
  589. /*
  590. * Likewise, these two variables are set up when the application
  591. * initialises, and inform all default-settings accesses after
  592. * that.
  593. */
  594. GLOBAL int default_protocol;
  595. GLOBAL int default_port;
  596. /*
  597. * This is set TRUE by cmdline.c iff a session is loaded with "-load".
  598. */
  599. GLOBAL int loaded_session;
  600. struct RSAKey; /* be a little careful of scope */
  601. /*
  602. * Mechanism for getting text strings such as usernames and passwords
  603. * from the front-end.
  604. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  605. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  606. *
  607. * Since many of the pieces of text involved may be chosen by the server,
  608. * the caller must take care to ensure that the server can't spoof locally-
  609. * generated prompts such as key passphrase prompts. Some ground rules:
  610. * - If the front-end needs to truncate a string, it should lop off the
  611. * end.
  612. * - The front-end should filter out any dangerous characters and
  613. * generally not trust the strings. (But \n is required to behave
  614. * vaguely sensibly, at least in `instruction', and ideally in
  615. * `prompt[]' too.)
  616. */
  617. typedef struct {
  618. char *prompt;
  619. int echo;
  620. char *result; /* allocated/freed by caller */
  621. size_t result_len;
  622. } prompt_t;
  623. typedef struct {
  624. /*
  625. * Indicates whether the information entered is to be used locally
  626. * (for instance a key passphrase prompt), or is destined for the wire.
  627. * This is a hint only; the front-end is at liberty not to use this
  628. * information (so the caller should ensure that the supplied text is
  629. * sufficient).
  630. */
  631. int to_server;
  632. char *name; /* Short description, perhaps for dialog box title */
  633. int name_reqd; /* Display of `name' required or optional? */
  634. char *instruction; /* Long description, maybe with embedded newlines */
  635. int instr_reqd; /* Display of `instruction' required or optional? */
  636. size_t n_prompts;
  637. prompt_t **prompts;
  638. void *frontend;
  639. void *data; /* slot for housekeeping data, managed by
  640. * get_userpass_input(); initially NULL */
  641. } prompts_t;
  642. prompts_t *new_prompts(void *frontend);
  643. void add_prompt(prompts_t *p, char *promptstr, int echo, size_t len);
  644. /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
  645. void free_prompts(prompts_t *p);
  646. /*
  647. * Exports from the front end.
  648. */
  649. void request_resize(void *frontend, int, int);
  650. void do_text(Context, int, int, wchar_t *, int, unsigned long, int);
  651. void do_cursor(Context, int, int, wchar_t *, int, unsigned long, int);
  652. int char_width(Context ctx, int uc);
  653. #ifdef OPTIMISE_SCROLL
  654. void do_scroll(Context, int, int, int);
  655. #endif
  656. void set_title(void *frontend, char *);
  657. void set_icon(void *frontend, char *);
  658. void set_sbar(void *frontend, int, int, int);
  659. Context get_ctx(void *frontend);
  660. void free_ctx(Context);
  661. void palette_set(void *frontend, int, int, int, int);
  662. void palette_reset(void *frontend);
  663. void write_aclip(void *frontend, char *, int, int);
  664. void write_clip(void *frontend, wchar_t *, int *, int, int);
  665. void get_clip(void *frontend, wchar_t **, int *);
  666. void optimised_move(void *frontend, int, int, int);
  667. void set_raw_mouse_mode(void *frontend, int);
  668. void connection_fatal(void *frontend, char *, ...);
  669. void fatalbox(char *, ...);
  670. void modalfatalbox(char *, ...);
  671. #ifdef macintosh
  672. #pragma noreturn(fatalbox)
  673. #pragma noreturn(modalfatalbox)
  674. #endif
  675. void do_beep(void *frontend, int);
  676. void begin_session(void *frontend);
  677. void sys_cursor(void *frontend, int x, int y);
  678. void request_paste(void *frontend);
  679. void frontend_keypress(void *frontend);
  680. void ldisc_update(void *frontend, int echo, int edit);
  681. /* It's the backend's responsibility to invoke this at the start of a
  682. * connection, if necessary; it can also invoke it later if the set of
  683. * special commands changes. It does not need to invoke it at session
  684. * shutdown. */
  685. void update_specials_menu(void *frontend);
  686. int from_backend(void *frontend, int is_stderr, const char *data, int len);
  687. int from_backend_untrusted(void *frontend, const char *data, int len);
  688. void notify_remote_exit(void *frontend);
  689. /* Get a sensible value for a tty mode. NULL return = don't set.
  690. * Otherwise, returned value should be freed by caller. */
  691. char *get_ttymode(void *frontend, const char *mode);
  692. /*
  693. * >0 = `got all results, carry on'
  694. * 0 = `user cancelled' (FIXME distinguish "give up entirely" and "next auth"?)
  695. * <0 = `please call back later with more in/inlen'
  696. */
  697. int get_userpass_input(prompts_t *p, unsigned char *in, int inlen);
  698. #define OPTIMISE_IS_SCROLL 1
  699. void set_iconic(void *frontend, int iconic);
  700. void move_window(void *frontend, int x, int y);
  701. void set_zorder(void *frontend, int top);
  702. void refresh_window(void *frontend);
  703. void set_zoomed(void *frontend, int zoomed);
  704. int is_iconic(void *frontend);
  705. void get_window_pos(void *frontend, int *x, int *y);
  706. void get_window_pixels(void *frontend, int *x, int *y);
  707. char *get_window_title(void *frontend, int icon);
  708. /* Hint from backend to frontend about time-consuming operations.
  709. * Initial state is assumed to be BUSY_NOT. */
  710. enum {
  711. BUSY_NOT, /* Not busy, all user interaction OK */
  712. BUSY_WAITING, /* Waiting for something; local event loops still running
  713. so some local interaction (e.g. menus) OK, but network
  714. stuff is suspended */
  715. BUSY_CPU /* Locally busy (e.g. crypto); user interaction suspended */
  716. };
  717. void set_busy_status(void *frontend, int status);
  718. void cleanup_exit(int);
  719. /*
  720. * Exports from noise.c.
  721. */
  722. void noise_get_heavy(void (*func) (void *, int));
  723. void noise_get_light(void (*func) (void *, int));
  724. void noise_regular(void);
  725. void noise_ultralight(unsigned long data);
  726. void random_save_seed(void);
  727. void random_destroy_seed(void);
  728. /*
  729. * Exports from settings.c.
  730. */
  731. char *save_settings(char *section, Config * cfg);
  732. void save_open_settings(void *sesskey, Config *cfg);
  733. void load_settings(char *section, Config * cfg);
  734. void load_open_settings(void *sesskey, Config *cfg);
  735. void get_sesslist(struct sesslist *, int allocate);
  736. void do_defaults(char *, Config *);
  737. void registry_cleanup(void);
  738. /*
  739. * Functions used by settings.c to provide platform-specific
  740. * default settings.
  741. *
  742. * (The integer one is expected to return `def' if it has no clear
  743. * opinion of its own. This is because there's no integer value
  744. * which I can reliably set aside to indicate `nil'. The string
  745. * function is perfectly all right returning NULL, of course. The
  746. * Filename and FontSpec functions are _not allowed_ to fail to
  747. * return, since these defaults _must_ be per-platform.)
  748. */
  749. char *platform_default_s(const char *name);
  750. int platform_default_i(const char *name, int def);
  751. Filename platform_default_filename(const char *name);
  752. FontSpec platform_default_fontspec(const char *name);
  753. /*
  754. * Exports from terminal.c.
  755. */
  756. Terminal *term_init(Config *, struct unicode_data *, void *);
  757. void term_free(Terminal *);
  758. void term_size(Terminal *, int, int, int);
  759. void term_paint(Terminal *, Context, int, int, int, int, int);
  760. void term_scroll(Terminal *, int, int);
  761. void term_pwron(Terminal *, int);
  762. void term_clrsb(Terminal *);
  763. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  764. int,int,int,int,int);
  765. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  766. unsigned int);
  767. void term_deselect(Terminal *);
  768. void term_update(Terminal *);
  769. void term_invalidate(Terminal *);
  770. void term_blink(Terminal *, int set_cursor);
  771. void term_do_paste(Terminal *);
  772. int term_paste_pending(Terminal *);
  773. void term_paste(Terminal *);
  774. void term_nopaste(Terminal *);
  775. int term_ldisc(Terminal *, int option);
  776. void term_copyall(Terminal *);
  777. void term_reconfig(Terminal *, Config *);
  778. void term_seen_key_event(Terminal *);
  779. int term_data(Terminal *, int is_stderr, const char *data, int len);
  780. int term_data_untrusted(Terminal *, const char *data, int len);
  781. void term_provide_resize_fn(Terminal *term,
  782. void (*resize_fn)(void *, int, int),
  783. void *resize_ctx);
  784. void term_provide_logctx(Terminal *term, void *logctx);
  785. void term_set_focus(Terminal *term, int has_focus);
  786. char *term_get_ttymode(Terminal *term, const char *mode);
  787. int term_get_userpass_input(Terminal *term, prompts_t *p,
  788. unsigned char *in, int inlen);
  789. /*
  790. * Exports from logging.c.
  791. */
  792. void *log_init(void *frontend, Config *cfg);
  793. void log_free(void *logctx);
  794. void log_reconfig(void *logctx, Config *cfg);
  795. void logfopen(void *logctx);
  796. void logfclose(void *logctx);
  797. void logtraffic(void *logctx, unsigned char c, int logmode);
  798. void logflush(void *logctx);
  799. void log_eventlog(void *logctx, const char *string);
  800. enum { PKT_INCOMING, PKT_OUTGOING };
  801. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  802. struct logblank_t {
  803. int offset;
  804. int len;
  805. int type;
  806. };
  807. void log_packet(void *logctx, int direction, int type,
  808. char *texttype, void *data, int len,
  809. int n_blanks, const struct logblank_t *blanks);
  810. /*
  811. * Exports from testback.c
  812. */
  813. extern Backend null_backend;
  814. extern Backend loop_backend;
  815. /*
  816. * Exports from raw.c.
  817. */
  818. extern Backend raw_backend;
  819. /*
  820. * Exports from rlogin.c.
  821. */
  822. extern Backend rlogin_backend;
  823. /*
  824. * Exports from telnet.c.
  825. */
  826. extern Backend telnet_backend;
  827. /*
  828. * Exports from ssh.c.
  829. */
  830. extern Backend ssh_backend;
  831. /*
  832. * Exports from ldisc.c.
  833. */
  834. void *ldisc_create(Config *, Terminal *, Backend *, void *, void *);
  835. void ldisc_free(void *);
  836. void ldisc_send(void *handle, char *buf, int len, int interactive);
  837. /*
  838. * Exports from ldiscucs.c.
  839. */
  840. void lpage_send(void *, int codepage, char *buf, int len, int interactive);
  841. void luni_send(void *, wchar_t * widebuf, int len, int interactive);
  842. /*
  843. * Exports from sshrand.c.
  844. */
  845. void random_add_noise(void *noise, int length);
  846. int random_byte(void);
  847. void random_get_savedata(void **data, int *len);
  848. extern int random_active;
  849. /* The random number subsystem is activated if at least one other entity
  850. * within the program expresses an interest in it. So each SSH session
  851. * calls random_ref on startup and random_unref on shutdown. */
  852. void random_ref(void);
  853. void random_unref(void);
  854. /*
  855. * Exports from pinger.c.
  856. */
  857. typedef struct pinger_tag *Pinger;
  858. Pinger pinger_new(Config *cfg, Backend *back, void *backhandle);
  859. void pinger_reconfig(Pinger, Config *oldcfg, Config *newcfg);
  860. void pinger_free(Pinger);
  861. /*
  862. * Exports from misc.c.
  863. */
  864. #include "misc.h"
  865. int cfg_launchable(const Config *cfg);
  866. char const *cfg_dest(const Config *cfg);
  867. /*
  868. * Exports from sercfg.c.
  869. */
  870. void ser_setup_config_box(struct controlbox *b, int midsession,
  871. int parity_mask, int flow_mask);
  872. /*
  873. * Exports from version.c.
  874. */
  875. extern char ver[];
  876. /*
  877. * Exports from unicode.c.
  878. */
  879. #ifndef CP_UTF8
  880. #define CP_UTF8 65001
  881. #endif
  882. /* void init_ucs(void); -- this is now in platform-specific headers */
  883. int is_dbcs_leadbyte(int codepage, char byte);
  884. int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
  885. wchar_t *wcstr, int wclen);
  886. int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
  887. char *mbstr, int mblen, char *defchr, int *defused,
  888. struct unicode_data *ucsdata);
  889. wchar_t xlat_uskbd2cyrllic(int ch);
  890. int check_compose(int first, int second);
  891. int decode_codepage(char *cp_name);
  892. const char *cp_enumerate (int index);
  893. const char *cp_name(int codepage);
  894. void get_unitab(int codepage, wchar_t * unitab, int ftype);
  895. /*
  896. * Exports from wcwidth.c
  897. */
  898. int mk_wcwidth(wchar_t ucs);
  899. int mk_wcswidth(const wchar_t *pwcs, size_t n);
  900. int mk_wcwidth_cjk(wchar_t ucs);
  901. int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n);
  902. /*
  903. * Exports from mscrypto.c
  904. */
  905. #ifdef MSCRYPTOAPI
  906. int crypto_startup();
  907. void crypto_wrapup();
  908. #endif
  909. /*
  910. * Exports from pageantc.c.
  911. *
  912. * agent_query returns 1 for here's-a-response, and 0 for query-in-
  913. * progress. In the latter case there will be a call to `callback'
  914. * at some future point, passing callback_ctx as the first
  915. * parameter and the actual reply data as the second and third.
  916. *
  917. * The response may be a NULL pointer (in either of the synchronous
  918. * or asynchronous cases), which indicates failure to receive a
  919. * response.
  920. */
  921. int agent_query(void *in, int inlen, void **out, int *outlen,
  922. void (*callback)(void *, void *, int), void *callback_ctx);
  923. int agent_exists(void);
  924. /*
  925. * Exports from wildcard.c
  926. */
  927. const char *wc_error(int value);
  928. int wc_match(const char *wildcard, const char *target);
  929. int wc_unescape(char *output, const char *wildcard);
  930. /*
  931. * Exports from frontend (windlg.c etc)
  932. */
  933. void logevent(void *frontend, const char *);
  934. void pgp_fingerprints(void);
  935. /*
  936. * verify_ssh_host_key() can return one of three values:
  937. *
  938. * - +1 means `key was OK' (either already known or the user just
  939. * approved it) `so continue with the connection'
  940. *
  941. * - 0 means `key was not OK, abandon the connection'
  942. *
  943. * - -1 means `I've initiated enquiries, please wait to be called
  944. * back via the provided function with a result that's either 0
  945. * or +1'.
  946. */
  947. int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
  948. char *keystr, char *fingerprint,
  949. void (*callback)(void *ctx, int result), void *ctx);
  950. /*
  951. * askalg has the same set of return values as verify_ssh_host_key.
  952. */
  953. int askalg(void *frontend, const char *algtype, const char *algname,
  954. void (*callback)(void *ctx, int result), void *ctx);
  955. /*
  956. * askappend can return four values:
  957. *
  958. * - 2 means overwrite the log file
  959. * - 1 means append to the log file
  960. * - 0 means cancel logging for this session
  961. * - -1 means please wait.
  962. */
  963. int askappend(void *frontend, Filename filename,
  964. void (*callback)(void *ctx, int result), void *ctx);
  965. #ifdef MPEXT
  966. void display_banner(void *frontend, const char* banner, int size);
  967. #endif
  968. /*
  969. * Exports from console frontends (wincons.c, uxcons.c)
  970. * that aren't equivalents to things in windlg.c et al.
  971. */
  972. extern int console_batch_mode;
  973. int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen);
  974. void console_provide_logctx(void *logctx);
  975. int is_interactive(void);
  976. /*
  977. * Exports from printing.c.
  978. */
  979. typedef struct printer_enum_tag printer_enum;
  980. typedef struct printer_job_tag printer_job;
  981. printer_enum *printer_start_enum(int *nprinters);
  982. char *printer_get_name(printer_enum *, int);
  983. void printer_finish_enum(printer_enum *);
  984. printer_job *printer_start_job(char *printer);
  985. void printer_job_data(printer_job *, void *, int);
  986. void printer_finish_job(printer_job *);
  987. /*
  988. * Exports from cmdline.c (and also cmdline_error(), which is
  989. * defined differently in various places and required _by_
  990. * cmdline.c).
  991. */
  992. int cmdline_process_param(char *, char *, int, Config *);
  993. void cmdline_run_saved(Config *);
  994. void cmdline_cleanup(void);
  995. int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen);
  996. #define TOOLTYPE_FILETRANSFER 1
  997. #define TOOLTYPE_NONNETWORK 2
  998. extern int cmdline_tooltype;
  999. void cmdline_error(char *, ...);
  1000. /*
  1001. * Exports from config.c.
  1002. */
  1003. struct controlbox;
  1004. void setup_config_box(struct controlbox *b, int midsession,
  1005. int protocol, int protcfginfo);
  1006. /*
  1007. * Exports from minibidi.c.
  1008. */
  1009. typedef struct bidi_char {
  1010. wchar_t origwc, wc;
  1011. unsigned short index;
  1012. } bidi_char;
  1013. int do_bidi(bidi_char *line, int count);
  1014. int do_shape(bidi_char *line, bidi_char *to, int count);
  1015. int is_rtl(int c);
  1016. /*
  1017. * X11 auth mechanisms we know about.
  1018. */
  1019. enum {
  1020. X11_NO_AUTH,
  1021. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  1022. X11_XDM, /* XDM-AUTHORIZATION-1 */
  1023. X11_NAUTHS
  1024. };
  1025. extern const char *const x11_authnames[]; /* declared in x11fwd.c */
  1026. /*
  1027. * Miscellaneous exports from the platform-specific code.
  1028. */
  1029. Filename filename_from_str(const char *string);
  1030. const char *filename_to_str(const Filename *fn);
  1031. int filename_equal(Filename f1, Filename f2);
  1032. int filename_is_null(Filename fn);
  1033. char *get_username(void); /* return value needs freeing */
  1034. char *get_random_data(int bytes); /* used in cmdgen.c */
  1035. /*
  1036. * Exports and imports from timing.c.
  1037. *
  1038. * schedule_timer() asks the front end to schedule a callback to a
  1039. * timer function in a given number of ticks. The returned value is
  1040. * the time (in ticks since an arbitrary offset) at which the
  1041. * callback can be expected. This value will also be passed as the
  1042. * `now' parameter to the callback function. Hence, you can (for
  1043. * example) schedule an event at a particular time by calling
  1044. * schedule_timer() and storing the return value in your context
  1045. * structure as the time when that event is due. The first time a
  1046. * callback function gives you that value or more as `now', you do
  1047. * the thing.
  1048. *
  1049. * expire_timer_context() drops all current timers associated with
  1050. * a given value of ctx (for when you're about to free ctx).
  1051. *
  1052. * run_timers() is called from the front end when it has reason to
  1053. * think some timers have reached their moment, or when it simply
  1054. * needs to know how long to wait next. We pass it the time we
  1055. * think it is. It returns TRUE and places the time when the next
  1056. * timer needs to go off in `next', or alternatively it returns
  1057. * FALSE if there are no timers at all pending.
  1058. *
  1059. * timer_change_notify() must be supplied by the front end; it
  1060. * notifies the front end that a new timer has been added to the
  1061. * list which is sooner than any existing ones. It provides the
  1062. * time when that timer needs to go off.
  1063. *
  1064. * *** FRONT END IMPLEMENTORS NOTE:
  1065. *
  1066. * There's an important subtlety in the front-end implementation of
  1067. * the timer interface. When a front end is given a `next' value,
  1068. * either returned from run_timers() or via timer_change_notify(),
  1069. * it should ensure that it really passes _that value_ as the `now'
  1070. * parameter to its next run_timers call. It should _not_ simply
  1071. * call GETTICKCOUNT() to get the `now' parameter when invoking
  1072. * run_timers().
  1073. *
  1074. * The reason for this is that an OS's system clock might not agree
  1075. * exactly with the timing mechanisms it supplies to wait for a
  1076. * given interval. I'll illustrate this by the simple example of
  1077. * Unix Plink, which uses timeouts to select() in a way which for
  1078. * these purposes can simply be considered to be a wait() function.
  1079. * Suppose, for the sake of argument, that this wait() function
  1080. * tends to return early by 1%. Then a possible sequence of actions
  1081. * is:
  1082. *
  1083. * - run_timers() tells the front end that the next timer firing
  1084. * is 10000ms from now.
  1085. * - Front end calls wait(10000ms), but according to
  1086. * GETTICKCOUNT() it has only waited for 9900ms.
  1087. * - Front end calls run_timers() again, passing time T-100ms as
  1088. * `now'.
  1089. * - run_timers() does nothing, and says the next timer firing is
  1090. * still 100ms from now.
  1091. * - Front end calls wait(100ms), which only waits for 99ms.
  1092. * - Front end calls run_timers() yet again, passing time T-1ms.
  1093. * - run_timers() says there's still 1ms to wait.
  1094. * - Front end calls wait(1ms).
  1095. *
  1096. * If you're _lucky_ at this point, wait(1ms) will actually wait
  1097. * for 1ms and you'll only have woken the program up three times.
  1098. * If you're unlucky, wait(1ms) might do nothing at all due to
  1099. * being below some minimum threshold, and you might find your
  1100. * program spends the whole of the last millisecond tight-looping
  1101. * between wait() and run_timers().
  1102. *
  1103. * Instead, what you should do is to _save_ the precise `next'
  1104. * value provided by run_timers() or via timer_change_notify(), and
  1105. * use that precise value as the input to the next run_timers()
  1106. * call. So:
  1107. *
  1108. * - run_timers() tells the front end that the next timer firing
  1109. * is at time T, 10000ms from now.
  1110. * - Front end calls wait(10000ms).
  1111. * - Front end then immediately calls run_timers() and passes it
  1112. * time T, without stopping to check GETTICKCOUNT() at all.
  1113. *
  1114. * This guarantees that the program wakes up only as many times as
  1115. * there are actual timer actions to be taken, and that the timing
  1116. * mechanism will never send it into a tight loop.
  1117. *
  1118. * (It does also mean that the timer action in the above example
  1119. * will occur 100ms early, but this is not generally critical. And
  1120. * the hypothetical 1% error in wait() will be partially corrected
  1121. * for anyway when, _after_ run_timers() returns, you call
  1122. * GETTICKCOUNT() and compare the result with the returned `next'
  1123. * value to find out how long you have to make your next wait().)
  1124. */
  1125. typedef void (*timer_fn_t)(void *ctx, long now);
  1126. long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  1127. void expire_timer_context(void *ctx);
  1128. int run_timers(long now, long *next);
  1129. void timer_change_notify(long next);
  1130. #endif