putty.h 65 KB

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