putty.h 63 KB

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