putty.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  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. bool 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. * We use the master list in sshsignals.h to define these enum
  191. * values, which will come out looking like names of the form
  192. * SS_SIGABRT, SS_SIGINT etc.
  193. */
  194. #define SIGNAL_MAIN(name, text) SS_SIG ## name,
  195. #define SIGNAL_SUB(name) SS_SIG ## name,
  196. #include "sshsignals.h"
  197. #undef SIGNAL_MAIN
  198. #undef SIGNAL_SUB
  199. /*
  200. * These aren't really special commands, but they appear in the
  201. * enumeration because the list returned from
  202. * backend_get_specials() will use them to specify the structure
  203. * of the GUI specials menu.
  204. */
  205. SS_SEP, /* Separator */
  206. SS_SUBMENU, /* Start a new submenu with specified name */
  207. SS_EXITMENU, /* Exit current submenu, or end of entire specials list */
  208. } SessionSpecialCode;
  209. /*
  210. * The structure type returned from backend_get_specials.
  211. */
  212. struct SessionSpecial {
  213. const char *name;
  214. SessionSpecialCode code;
  215. int arg;
  216. };
  217. /* Needed by both sshchan.h and sshppl.h */
  218. typedef void (*add_special_fn_t)(
  219. void *ctx, const char *text, SessionSpecialCode code, int arg);
  220. typedef enum {
  221. MBT_NOTHING,
  222. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  223. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  224. MBT_WHEEL_UP, MBT_WHEEL_DOWN /* mouse wheel */
  225. } Mouse_Button;
  226. typedef enum {
  227. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
  228. } Mouse_Action;
  229. /* Keyboard modifiers -- keys the user is actually holding down */
  230. #define PKM_SHIFT 0x01
  231. #define PKM_CONTROL 0x02
  232. #define PKM_META 0x04
  233. #define PKM_ALT 0x08
  234. /* Keyboard flags that aren't really modifiers */
  235. #define PKF_CAPSLOCK 0x10
  236. #define PKF_NUMLOCK 0x20
  237. #define PKF_REPEAT 0x40
  238. /* Stand-alone keysyms for function keys */
  239. typedef enum {
  240. PK_NULL, /* No symbol for this key */
  241. /* Main keypad keys */
  242. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  243. /* Editing keys */
  244. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  245. /* Cursor keys */
  246. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  247. /* Numeric keypad */ /* Real one looks like: */
  248. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  249. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  250. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  251. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  252. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  253. /* Top row */
  254. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  255. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  256. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  257. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  258. PK_PAUSE
  259. } Key_Sym;
  260. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  261. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  262. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  263. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  264. enum {
  265. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  266. };
  267. enum {
  268. /*
  269. * SSH-2 key exchange algorithms
  270. */
  271. KEX_WARN,
  272. KEX_DHGROUP1,
  273. KEX_DHGROUP14,
  274. KEX_DHGEX,
  275. KEX_RSA,
  276. KEX_ECDH,
  277. KEX_MAX
  278. };
  279. enum {
  280. /*
  281. * SSH-2 host key algorithms
  282. */
  283. HK_WARN,
  284. HK_RSA,
  285. HK_DSA,
  286. HK_ECDSA,
  287. HK_ED25519,
  288. HK_MAX
  289. };
  290. enum {
  291. /*
  292. * SSH ciphers (both SSH-1 and SSH-2)
  293. */
  294. CIPHER_WARN, /* pseudo 'cipher' */
  295. CIPHER_3DES,
  296. CIPHER_BLOWFISH,
  297. CIPHER_AES, /* (SSH-2 only) */
  298. CIPHER_DES,
  299. CIPHER_ARCFOUR,
  300. CIPHER_CHACHA20,
  301. CIPHER_MAX /* no. ciphers (inc warn) */
  302. };
  303. enum {
  304. /*
  305. * Several different bits of the PuTTY configuration seem to be
  306. * three-way settings whose values are `always yes', `always
  307. * no', and `decide by some more complex automated means'. This
  308. * is true of line discipline options (local echo and line
  309. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  310. * SSH server bug workarounds. Accordingly I supply a single enum
  311. * here to deal with them all.
  312. */
  313. FORCE_ON, FORCE_OFF, AUTO
  314. };
  315. enum {
  316. /*
  317. * Proxy types.
  318. */
  319. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  320. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_FUZZ
  321. };
  322. enum {
  323. /*
  324. * Line discipline options which the backend might try to control.
  325. */
  326. LD_EDIT, /* local line editing */
  327. LD_ECHO, /* local echo */
  328. LD_N_OPTIONS
  329. };
  330. enum {
  331. /* Actions on remote window title query */
  332. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  333. };
  334. enum {
  335. /* Protocol back ends. (CONF_protocol) */
  336. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
  337. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  338. * hurt to define it globally. */
  339. PROT_SERIAL
  340. };
  341. enum {
  342. /* Bell settings (CONF_beep) */
  343. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  344. };
  345. enum {
  346. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  347. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  348. };
  349. enum {
  350. /* Resize actions (CONF_resize_action) */
  351. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  352. };
  353. enum {
  354. /* Function key types (CONF_funky_type) */
  355. FUNKY_TILDE,
  356. FUNKY_LINUX,
  357. FUNKY_XTERM,
  358. FUNKY_VT400,
  359. FUNKY_VT100P,
  360. FUNKY_SCO
  361. };
  362. enum {
  363. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  364. };
  365. enum {
  366. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  367. };
  368. enum {
  369. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  370. };
  371. /*
  372. * Tables of string <-> enum value mappings used in settings.c.
  373. * Defined here so that backends can export their GSS library tables
  374. * to the cross-platform settings code.
  375. */
  376. struct keyvalwhere {
  377. /*
  378. * Two fields which define a string and enum value to be
  379. * equivalent to each other.
  380. */
  381. const char *s;
  382. int v;
  383. /*
  384. * The next pair of fields are used by gprefs() in settings.c to
  385. * arrange that when it reads a list of strings representing a
  386. * preference list and translates it into the corresponding list
  387. * of integers, strings not appearing in the list are entered in a
  388. * configurable position rather than uniformly at the end.
  389. */
  390. /*
  391. * 'vrel' indicates which other value in the list to place this
  392. * element relative to. It should be a value that has occurred in
  393. * a 'v' field of some other element of the array, or -1 to
  394. * indicate that we simply place relative to one or other end of
  395. * the list.
  396. *
  397. * gprefs will try to process the elements in an order which makes
  398. * this field work (i.e. so that the element referenced has been
  399. * added before processing this one).
  400. */
  401. int vrel;
  402. /*
  403. * 'where' indicates whether to place the new value before or
  404. * after the one referred to by vrel. -1 means before; +1 means
  405. * after.
  406. *
  407. * When vrel is -1, this also implicitly indicates which end of
  408. * the array to use. So vrel=-1, where=-1 means to place _before_
  409. * some end of the list (hence, at the last element); vrel=-1,
  410. * where=+1 means to place _after_ an end (hence, at the first).
  411. */
  412. int where;
  413. };
  414. #ifndef NO_GSSAPI
  415. extern const int ngsslibs;
  416. extern const char *const gsslibnames[]; /* for displaying in configuration */
  417. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  418. #endif
  419. extern const char *const ttymodes[];
  420. enum {
  421. /*
  422. * Network address types. Used for specifying choice of IPv4/v6
  423. * in config; also used in proxy.c to indicate whether a given
  424. * host name has already been resolved or will be resolved at
  425. * the proxy end.
  426. */
  427. ADDRTYPE_UNSPEC,
  428. ADDRTYPE_IPV4,
  429. ADDRTYPE_IPV6,
  430. ADDRTYPE_LOCAL, /* e.g. Unix domain socket, or Windows named pipe */
  431. ADDRTYPE_NAME /* SockAddr storing an unresolved host name */
  432. };
  433. struct Backend {
  434. const BackendVtable *vt;
  435. };
  436. struct BackendVtable {
  437. const char *(*init) (Seat *seat, Backend **backend_out,
  438. LogContext *logctx, Conf *conf,
  439. const char *host, int port,
  440. char **realhost, bool nodelay, bool keepalive);
  441. void (*free) (Backend *be);
  442. /* Pass in a replacement configuration. */
  443. void (*reconfig) (Backend *be, Conf *conf);
  444. /* send() returns the current amount of buffered data. */
  445. int (*send) (Backend *be, const char *buf, int len);
  446. /* sendbuffer() does the same thing but without attempting a send */
  447. int (*sendbuffer) (Backend *be);
  448. void (*size) (Backend *be, int width, int height);
  449. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  450. const SessionSpecial *(*get_specials) (Backend *be);
  451. bool (*connected) (Backend *be);
  452. int (*exitcode) (Backend *be);
  453. /* If back->sendok() returns false, the backend doesn't currently
  454. * want input data, so the frontend should avoid acquiring any if
  455. * possible (passing back-pressure on to its sender). */
  456. bool (*sendok) (Backend *be);
  457. bool (*ldisc_option_state) (Backend *be, int);
  458. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  459. /* Tells the back end that the front end buffer is clearing. */
  460. void (*unthrottle) (Backend *be, int bufsize);
  461. int (*cfg_info) (Backend *be);
  462. /* Only implemented in the SSH protocol: check whether a
  463. * connection-sharing upstream exists for a given configuration. */
  464. bool (*test_for_upstream)(const char *host, int port, Conf *conf);
  465. const char *name;
  466. int protocol;
  467. int default_port;
  468. };
  469. #define backend_init(vt, seat, out, logctx, conf, host, port, rhost, nd, ka) \
  470. ((vt)->init(seat, out, logctx, conf, host, port, rhost, nd, ka))
  471. #define backend_free(be) ((be)->vt->free(be))
  472. #define backend_reconfig(be, conf) ((be)->vt->reconfig(be, conf))
  473. #define backend_send(be, buf, len) ((be)->vt->send(be, buf, len))
  474. #define backend_sendbuffer(be) ((be)->vt->sendbuffer(be))
  475. #define backend_size(be, w, h) ((be)->vt->size(be, w, h))
  476. #define backend_special(be, code, arg) ((be)->vt->special(be, code, arg))
  477. #define backend_get_specials(be) ((be)->vt->get_specials(be))
  478. #define backend_connected(be) ((be)->vt->connected(be))
  479. #define backend_exitcode(be) ((be)->vt->exitcode(be))
  480. #define backend_sendok(be) ((be)->vt->sendok(be))
  481. #define backend_ldisc_option_state(be, opt) \
  482. ((be)->vt->ldisc_option_state(be, opt))
  483. #define backend_provide_ldisc(be, ldisc) ((be)->vt->provide_ldisc(be, ldisc))
  484. #define backend_unthrottle(be, bufsize) ((be)->vt->unthrottle(be, bufsize))
  485. #define backend_cfg_info(be) ((be)->vt->cfg_info(be))
  486. extern const struct BackendVtable *const backends[];
  487. /*
  488. * Suggested default protocol provided by the backend link module.
  489. * The application is free to ignore this.
  490. */
  491. extern const int be_default_protocol;
  492. /*
  493. * Name of this particular application, for use in the config box
  494. * and other pieces of text.
  495. */
  496. extern const char *const appname;
  497. /*
  498. * Some global flags denoting the type of application.
  499. *
  500. * FLAG_VERBOSE is set when the user requests verbose details.
  501. *
  502. * FLAG_INTERACTIVE is set when a full interactive shell session is
  503. * being run, _either_ because no remote command has been provided
  504. * _or_ because the application is GUI and can't run non-
  505. * interactively.
  506. *
  507. * These flags describe the type of _application_ - they wouldn't
  508. * vary between individual sessions - and so it's OK to have this
  509. * variable be GLOBAL.
  510. *
  511. * Note that additional flags may be defined in platform-specific
  512. * headers. It's probably best if those ones start from 0x1000, to
  513. * avoid collision.
  514. */
  515. #define FLAG_VERBOSE 0x0001
  516. #define FLAG_INTERACTIVE 0x0002
  517. GLOBAL int flags;
  518. /*
  519. * Likewise, these two variables are set up when the application
  520. * initialises, and inform all default-settings accesses after
  521. * that.
  522. */
  523. GLOBAL int default_protocol;
  524. GLOBAL int default_port;
  525. /*
  526. * This is set true by cmdline.c iff a session is loaded with "-load".
  527. */
  528. GLOBAL bool loaded_session;
  529. /*
  530. * This is set to the name of the loaded session.
  531. */
  532. GLOBAL char *cmdline_session_name;
  533. /*
  534. * Mechanism for getting text strings such as usernames and passwords
  535. * from the front-end.
  536. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  537. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  538. *
  539. * Since many of the pieces of text involved may be chosen by the server,
  540. * the caller must take care to ensure that the server can't spoof locally-
  541. * generated prompts such as key passphrase prompts. Some ground rules:
  542. * - If the front-end needs to truncate a string, it should lop off the
  543. * end.
  544. * - The front-end should filter out any dangerous characters and
  545. * generally not trust the strings. (But \n is required to behave
  546. * vaguely sensibly, at least in `instruction', and ideally in
  547. * `prompt[]' too.)
  548. */
  549. typedef struct {
  550. char *prompt;
  551. bool echo;
  552. /*
  553. * 'result' must be a dynamically allocated array of exactly
  554. * 'resultsize' chars. The code for actually reading input may
  555. * realloc it bigger (and adjust resultsize accordingly) if it has
  556. * to. The caller should free it again when finished with it.
  557. *
  558. * If resultsize==0, then result may be NULL. When setting up a
  559. * prompt_t, it's therefore easiest to initialise them this way,
  560. * which means all actual allocation is done by the callee. This
  561. * is what add_prompt does.
  562. */
  563. char *result;
  564. size_t resultsize;
  565. } prompt_t;
  566. typedef struct {
  567. /*
  568. * Indicates whether the information entered is to be used locally
  569. * (for instance a key passphrase prompt), or is destined for the wire.
  570. * This is a hint only; the front-end is at liberty not to use this
  571. * information (so the caller should ensure that the supplied text is
  572. * sufficient).
  573. */
  574. bool to_server;
  575. char *name; /* Short description, perhaps for dialog box title */
  576. bool name_reqd; /* Display of `name' required or optional? */
  577. char *instruction; /* Long description, maybe with embedded newlines */
  578. bool instr_reqd; /* Display of `instruction' required or optional? */
  579. size_t n_prompts; /* May be zero (in which case display the foregoing,
  580. * if any, and return success) */
  581. prompt_t **prompts;
  582. void *data; /* slot for housekeeping data, managed by
  583. * seat_get_userpass_input(); initially NULL */
  584. } prompts_t;
  585. prompts_t *new_prompts();
  586. void add_prompt(prompts_t *p, char *promptstr, bool echo);
  587. void prompt_set_result(prompt_t *pr, const char *newstr);
  588. void prompt_ensure_result_size(prompt_t *pr, int len);
  589. /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
  590. void free_prompts(prompts_t *p);
  591. /*
  592. * Data type definitions for true-colour terminal display.
  593. * 'optionalrgb' describes a single RGB colour, which overrides the
  594. * other colour settings if 'enabled' is nonzero, and is ignored
  595. * otherwise. 'truecolour' contains a pair of those for foreground and
  596. * background.
  597. */
  598. typedef struct optionalrgb {
  599. bool enabled;
  600. unsigned char r, g, b;
  601. } optionalrgb;
  602. extern const optionalrgb optionalrgb_none;
  603. typedef struct truecolour {
  604. optionalrgb fg, bg;
  605. } truecolour;
  606. #define optionalrgb_equal(r1,r2) ( \
  607. (r1).enabled==(r2).enabled && \
  608. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  609. #define truecolour_equal(c1,c2) ( \
  610. optionalrgb_equal((c1).fg, (c2).fg) && \
  611. optionalrgb_equal((c1).bg, (c2).bg))
  612. /*
  613. * Enumeration of clipboards. We provide some standard ones cross-
  614. * platform, and then permit each platform to extend this enumeration
  615. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  616. *
  617. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  618. * from which return no data.
  619. *
  620. * CLIP_LOCAL refers to a buffer within terminal.c, which
  621. * unconditionally saves the last data selected in the terminal. In
  622. * configurations where a system clipboard is not written
  623. * automatically on selection but instead by an explicit UI action,
  624. * this is where the code responding to that action can find the data
  625. * to write to the clipboard in question.
  626. */
  627. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  628. X(CLIP_NULL, "null clipboard") \
  629. X(CLIP_LOCAL, "last text selected in terminal") \
  630. /* end of list */
  631. #define ALL_CLIPBOARDS(X) \
  632. CROSS_PLATFORM_CLIPBOARDS(X) \
  633. PLATFORM_CLIPBOARDS(X) \
  634. /* end of list */
  635. #define CLIP_ID(id,name) id,
  636. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  637. #undef CLIP_ID
  638. /* Hint from backend to frontend about time-consuming operations, used
  639. * by seat_set_busy_status. Initial state is assumed to be
  640. * BUSY_NOT. */
  641. typedef enum BusyStatus {
  642. BUSY_NOT, /* Not busy, all user interaction OK */
  643. BUSY_WAITING, /* Waiting for something; local event loops still
  644. running so some local interaction (e.g. menus)
  645. OK, but network stuff is suspended */
  646. BUSY_CPU /* Locally busy (e.g. crypto); user interaction
  647. * suspended */
  648. } BusyStatus;
  649. /*
  650. * Data type 'Seat', which is an API intended to contain essentially
  651. * everything that a back end might need to talk to its client for:
  652. * session output, password prompts, SSH warnings about host keys and
  653. * weak cryptography, notifications of events like the remote process
  654. * exiting or the GUI specials menu needing an update.
  655. */
  656. struct Seat {
  657. const struct SeatVtable *vt;
  658. };
  659. struct SeatVtable {
  660. /*
  661. * Provide output from the remote session. 'is_stderr' indicates
  662. * that the output should be sent to a separate error message
  663. * channel, if the seat has one. But combining both channels into
  664. * one is OK too; that's what terminal-window based seats do.
  665. *
  666. * The return value is the current size of the output backlog.
  667. */
  668. int (*output)(Seat *seat, bool is_stderr, const void *data, int len);
  669. /*
  670. * Called when the back end wants to indicate that EOF has arrived
  671. * on the server-to-client stream. Returns false to indicate that
  672. * we intend to keep the session open in the other direction, or
  673. * true to indicate that if they're closing so are we.
  674. */
  675. bool (*eof)(Seat *seat);
  676. /*
  677. * Try to get answers from a set of interactive login prompts. The
  678. * prompts are provided in 'p'; the bufchain 'input' holds the
  679. * data currently outstanding in the session's normal standard-
  680. * input channel. Seats may implement this function by consuming
  681. * data from 'input' (e.g. password prompts in GUI PuTTY,
  682. * displayed in the same terminal as the subsequent session), or
  683. * by doing something entirely different (e.g. directly
  684. * interacting with standard I/O, or putting up a dialog box).
  685. *
  686. * A positive return value means that all prompts have had answers
  687. * filled in. A zero return means that the user performed a
  688. * deliberate 'cancel' UI action. A negative return means that no
  689. * answer can be given yet but please try again later.
  690. *
  691. * (FIXME: it would be nice to distinguish two classes of cancel
  692. * action, so the user could specify 'I want to abandon this
  693. * entire attempt to start a session' or the milder 'I want to
  694. * abandon this particular form of authentication and fall back to
  695. * a different one' - e.g. if you turn out not to be able to
  696. * remember your private key passphrase then perhaps you'd rather
  697. * fall back to password auth rather than aborting the whole
  698. * session.)
  699. *
  700. * (Also FIXME: currently, backends' only response to the 'try
  701. * again later' is to try again when more input data becomes
  702. * available, because they assume that a seat is returning that
  703. * value because it's consuming keyboard input. But a seat that
  704. * handled this function by putting up a dialog box might want to
  705. * put it up non-modally, and therefore would want to proactively
  706. * notify the backend to retry once the dialog went away. So if I
  707. * ever do want to move password prompts into a dialog box, I'll
  708. * want a backend method for sending that notification.)
  709. */
  710. int (*get_userpass_input)(Seat *seat, prompts_t *p, bufchain *input);
  711. /*
  712. * Notify the seat that the process running at the other end of
  713. * the connection has finished.
  714. */
  715. void (*notify_remote_exit)(Seat *seat);
  716. /*
  717. * Notify the seat that the connection has suffered a fatal error.
  718. */
  719. void (*connection_fatal)(Seat *seat, const char *message);
  720. /*
  721. * Notify the seat that the list of special commands available
  722. * from backend_get_specials() has changed, so that it might want
  723. * to call that function to repopulate its menu.
  724. *
  725. * Seats are not expected to call backend_get_specials()
  726. * proactively; they may start by assuming that the backend
  727. * provides no special commands at all, so if the backend does
  728. * provide any, then it should use this notification at startup
  729. * time. Of course it can also invoke it later if the set of
  730. * special commands changes.
  731. *
  732. * It does not need to invoke it at session shutdown.
  733. */
  734. void (*update_specials_menu)(Seat *seat);
  735. /*
  736. * Get the seat's preferred value for an SSH terminal mode
  737. * setting. Returning NULL indicates no preference (i.e. the SSH
  738. * connection will not attempt to set the mode at all).
  739. *
  740. * The returned value is dynamically allocated, and the caller
  741. * should free it.
  742. */
  743. char *(*get_ttymode)(Seat *seat, const char *mode);
  744. /*
  745. * Tell the seat whether the backend is currently doing anything
  746. * CPU-intensive (typically a cryptographic key exchange). See
  747. * BusyStatus enumeration above.
  748. */
  749. void (*set_busy_status)(Seat *seat, BusyStatus status);
  750. /*
  751. * Ask the seat whether a given SSH host key should be accepted.
  752. * This may return immediately after checking saved configuration
  753. * or command-line options, or it may have to present a prompt to
  754. * the user and return asynchronously later.
  755. *
  756. * Return values:
  757. *
  758. * - +1 means `key was OK' (either already known or the user just
  759. * approved it) `so continue with the connection'
  760. *
  761. * - 0 means `key was not OK, abandon the connection'
  762. *
  763. * - -1 means `I've initiated enquiries, please wait to be called
  764. * back via the provided function with a result that's either 0
  765. * or +1'.
  766. */
  767. int (*verify_ssh_host_key)(
  768. Seat *seat, const char *host, int port,
  769. const char *keytype, char *keystr, char *key_fingerprint,
  770. void (*callback)(void *ctx, int result), void *ctx);
  771. /*
  772. * Check with the seat whether it's OK to use a cryptographic
  773. * primitive from below the 'warn below this line' threshold in
  774. * the input Conf. Return values are the same as
  775. * verify_ssh_host_key above.
  776. */
  777. int (*confirm_weak_crypto_primitive)(
  778. Seat *seat, const char *algtype, const char *algname,
  779. void (*callback)(void *ctx, int result), void *ctx);
  780. /*
  781. * Variant form of confirm_weak_crypto_primitive, which prints a
  782. * slightly different message but otherwise has the same
  783. * semantics.
  784. *
  785. * This form is used in the case where we're using a host key
  786. * below the warning threshold because that's the best one we have
  787. * cached, but at least one host key algorithm *above* the
  788. * threshold is available that we don't have cached. 'betteralgs'
  789. * lists the better algorithm(s).
  790. */
  791. int (*confirm_weak_cached_hostkey)(
  792. Seat *seat, const char *algname, const char *betteralgs,
  793. void (*callback)(void *ctx, int result), void *ctx);
  794. /*
  795. * Indicates whether the seat is expecting to interact with the
  796. * user in the UTF-8 character set. (Affects e.g. visual erase
  797. * handling in local line editing.)
  798. */
  799. bool (*is_utf8)(Seat *seat);
  800. /*
  801. * Notify the seat that the back end, and/or the ldisc between
  802. * them, have changed their idea of whether they currently want
  803. * local echo and/or local line editing enabled.
  804. */
  805. void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
  806. /*
  807. * Return the local X display string relevant to a seat, or NULL
  808. * if there isn't one or if the concept is meaningless.
  809. */
  810. const char *(*get_x_display)(Seat *seat);
  811. /*
  812. * Return the X11 id of the X terminal window relevant to a seat,
  813. * by returning true and filling in the output pointer. Return
  814. * false if there isn't one or if the concept is meaningless.
  815. */
  816. bool (*get_windowid)(Seat *seat, long *id_out);
  817. /*
  818. * Return the size of the terminal window in pixels. If the
  819. * concept is meaningless or the information is unavailable,
  820. * return false; otherwise fill in the output pointers and return
  821. * true.
  822. */
  823. bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
  824. };
  825. #define seat_output(seat, is_stderr, data, len) \
  826. ((seat)->vt->output(seat, is_stderr, data, len))
  827. #define seat_eof(seat) \
  828. ((seat)->vt->eof(seat))
  829. #define seat_get_userpass_input(seat, p, input) \
  830. ((seat)->vt->get_userpass_input(seat, p, input))
  831. #define seat_notify_remote_exit(seat) \
  832. ((seat)->vt->notify_remote_exit(seat))
  833. #define seat_update_specials_menu(seat) \
  834. ((seat)->vt->update_specials_menu(seat))
  835. #define seat_get_ttymode(seat, mode) \
  836. ((seat)->vt->get_ttymode(seat, mode))
  837. #define seat_set_busy_status(seat, status) \
  838. ((seat)->vt->set_busy_status(seat, status))
  839. #define seat_verify_ssh_host_key(seat, h, p, typ, str, fp, cb, ctx) \
  840. ((seat)->vt->verify_ssh_host_key(seat, h, p, typ, str, fp, cb, ctx))
  841. #define seat_confirm_weak_crypto_primitive(seat, typ, alg, cb, ctx) \
  842. ((seat)->vt->confirm_weak_crypto_primitive(seat, typ, alg, cb, ctx))
  843. #define seat_confirm_weak_cached_hostkey(seat, alg, better, cb, ctx) \
  844. ((seat)->vt->confirm_weak_cached_hostkey(seat, alg, better, cb, ctx))
  845. #define seat_is_utf8(seat) \
  846. ((seat)->vt->is_utf8(seat))
  847. #define seat_echoedit_update(seat, echoing, editing) \
  848. ((seat)->vt->echoedit_update(seat, echoing, editing))
  849. #define seat_get_x_display(seat) \
  850. ((seat)->vt->get_x_display(seat))
  851. #define seat_get_windowid(seat, out) \
  852. ((seat)->vt->get_windowid(seat, out))
  853. #define seat_get_window_pixel_size(seat, width, height) \
  854. ((seat)->vt->get_window_pixel_size(seat, width, height))
  855. /* Unlike the seat's actual method, the public entry point
  856. * seat_connection_fatal is a wrapper function with a printf-like API,
  857. * defined in misc.c. */
  858. void seat_connection_fatal(Seat *seat, const char *fmt, ...);
  859. /* Handy aliases for seat_output which set is_stderr to a fixed value. */
  860. #define seat_stdout(seat, data, len) \
  861. seat_output(seat, false, data, len)
  862. #define seat_stderr(seat, data, len) \
  863. seat_output(seat, true, data, len)
  864. /*
  865. * Stub methods for seat implementations that want to use the obvious
  866. * null handling for a given method.
  867. *
  868. * These are generally obvious, except for is_utf8, where you might
  869. * plausibly want to return either fixed answer 'no' or 'yes'.
  870. */
  871. int nullseat_output(Seat *seat, bool is_stderr, const void *data, int len);
  872. bool nullseat_eof(Seat *seat);
  873. int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
  874. void nullseat_notify_remote_exit(Seat *seat);
  875. void nullseat_connection_fatal(Seat *seat, const char *message);
  876. void nullseat_update_specials_menu(Seat *seat);
  877. char *nullseat_get_ttymode(Seat *seat, const char *mode);
  878. void nullseat_set_busy_status(Seat *seat, BusyStatus status);
  879. int nullseat_verify_ssh_host_key(
  880. Seat *seat, const char *host, int port,
  881. const char *keytype, char *keystr, char *key_fingerprint,
  882. void (*callback)(void *ctx, int result), void *ctx);
  883. int nullseat_confirm_weak_crypto_primitive(
  884. Seat *seat, const char *algtype, const char *algname,
  885. void (*callback)(void *ctx, int result), void *ctx);
  886. int nullseat_confirm_weak_cached_hostkey(
  887. Seat *seat, const char *algname, const char *betteralgs,
  888. void (*callback)(void *ctx, int result), void *ctx);
  889. bool nullseat_is_never_utf8(Seat *seat);
  890. bool nullseat_is_always_utf8(Seat *seat);
  891. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
  892. const char *nullseat_get_x_display(Seat *seat);
  893. bool nullseat_get_windowid(Seat *seat, long *id_out);
  894. bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
  895. /*
  896. * Seat functions provided by the platform's console-application
  897. * support module (wincons.c, uxcons.c).
  898. */
  899. void console_connection_fatal(Seat *seat, const char *message);
  900. int console_verify_ssh_host_key(
  901. Seat *seat, const char *host, int port,
  902. const char *keytype, char *keystr, char *key_fingerprint,
  903. void (*callback)(void *ctx, int result), void *ctx);
  904. int console_confirm_weak_crypto_primitive(
  905. Seat *seat, const char *algtype, const char *algname,
  906. void (*callback)(void *ctx, int result), void *ctx);
  907. int console_confirm_weak_cached_hostkey(
  908. Seat *seat, const char *algname, const char *betteralgs,
  909. void (*callback)(void *ctx, int result), void *ctx);
  910. /*
  911. * Other centralised seat functions.
  912. */
  913. int filexfer_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
  914. /*
  915. * Data type 'TermWin', which is a vtable encapsulating all the
  916. * functionality that Terminal expects from its containing terminal
  917. * window.
  918. */
  919. struct TermWin {
  920. const struct TermWinVtable *vt;
  921. };
  922. struct TermWinVtable {
  923. /*
  924. * All functions listed here between setup_draw_ctx and
  925. * free_draw_ctx expect to be _called_ between them too, so that
  926. * the TermWin has a drawing context currently available.
  927. *
  928. * (Yes, even char_width, because e.g. the Windows implementation
  929. * of TermWin handles it by loading the currently configured font
  930. * into the HDC and doing a GDI query.)
  931. */
  932. bool (*setup_draw_ctx)(TermWin *);
  933. /* Draw text in the window, during a painting operation */
  934. void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
  935. unsigned long attrs, int line_attrs, truecolour tc);
  936. /* Draw the visible cursor. Expects you to have called do_text
  937. * first (because it might just draw an underline over a character
  938. * presumed to exist already), but also expects you to pass in all
  939. * the details of the character under the cursor (because it might
  940. * redraw it in different colours). */
  941. void (*draw_cursor)(TermWin *, int x, int y, wchar_t *text, int len,
  942. unsigned long attrs, int line_attrs, truecolour tc);
  943. int (*char_width)(TermWin *, int uc);
  944. void (*free_draw_ctx)(TermWin *);
  945. void (*set_cursor_pos)(TermWin *, int x, int y);
  946. void (*set_raw_mouse_mode)(TermWin *, bool enable);
  947. void (*set_scrollbar)(TermWin *, int total, int start, int page);
  948. void (*bell)(TermWin *, int mode);
  949. void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
  950. truecolour *colours, int len, bool must_deselect);
  951. void (*clip_request_paste)(TermWin *, int clipboard);
  952. void (*refresh)(TermWin *);
  953. void (*request_resize)(TermWin *, int w, int h);
  954. void (*set_title)(TermWin *, const char *title);
  955. void (*set_icon_title)(TermWin *, const char *icontitle);
  956. /* set_minimised and set_maximised are assumed to set two
  957. * independent settings, rather than a single three-way
  958. * {min,normal,max} switch. The idea is that when you un-minimise
  959. * the window it remembers whether to go back to normal or
  960. * maximised. */
  961. void (*set_minimised)(TermWin *, bool minimised);
  962. bool (*is_minimised)(TermWin *);
  963. void (*set_maximised)(TermWin *, bool maximised);
  964. void (*move)(TermWin *, int x, int y);
  965. void (*set_zorder)(TermWin *, bool top);
  966. bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
  967. void (*palette_set)(TermWin *, int n, int r, int g, int b);
  968. void (*palette_reset)(TermWin *);
  969. void (*get_pos)(TermWin *, int *x, int *y);
  970. void (*get_pixels)(TermWin *, int *x, int *y);
  971. const char *(*get_title)(TermWin *, bool icon);
  972. bool (*is_utf8)(TermWin *);
  973. };
  974. #define win_setup_draw_ctx(win) \
  975. ((win)->vt->setup_draw_ctx(win))
  976. #define win_draw_text(win, x, y, text, len, attrs, lattrs, tc) \
  977. ((win)->vt->draw_text(win, x, y, text, len, attrs, lattrs, tc))
  978. #define win_draw_cursor(win, x, y, text, len, attrs, lattrs, tc) \
  979. ((win)->vt->draw_cursor(win, x, y, text, len, attrs, lattrs, tc))
  980. #define win_char_width(win, uc) \
  981. ((win)->vt->char_width(win, uc))
  982. #define win_free_draw_ctx(win) \
  983. ((win)->vt->free_draw_ctx(win))
  984. #define win_set_cursor_pos(win, x, y) \
  985. ((win)->vt->set_cursor_pos(win, x, y))
  986. #define win_set_raw_mouse_mode(win, enable) \
  987. ((win)->vt->set_raw_mouse_mode(win, enable))
  988. #define win_set_scrollbar(win, total, start, page) \
  989. ((win)->vt->set_scrollbar(win, total, start, page))
  990. #define win_bell(win, mode) \
  991. ((win)->vt->bell(win, mode))
  992. #define win_clip_write(win, clipboard, text, attrs, colours, len, desel) \
  993. ((win)->vt->clip_write(win, clipboard, text, attrs, colours, len, desel))
  994. #define win_clip_request_paste(win, clipboard) \
  995. ((win)->vt->clip_request_paste(win, clipboard))
  996. #define win_refresh(win) \
  997. ((win)->vt->refresh(win))
  998. #define win_request_resize(win, w, h) \
  999. ((win)->vt->request_resize(win, w, h))
  1000. #define win_set_title(win, title) \
  1001. ((win)->vt->set_title(win, title))
  1002. #define win_set_icon_title(win, ititle) \
  1003. ((win)->vt->set_icon_title(win, ititle))
  1004. #define win_set_minimised(win, minimised) \
  1005. ((win)->vt->set_minimised(win, minimised))
  1006. #define win_is_minimised(win) \
  1007. ((win)->vt->is_minimised(win))
  1008. #define win_set_maximised(win, maximised) \
  1009. ((win)->vt->set_maximised(win, maximised))
  1010. #define win_move(win, x, y) \
  1011. ((win)->vt->move(win, x, y))
  1012. #define win_set_zorder(win, top) \
  1013. ((win)->vt->set_zorder(win, top))
  1014. #define win_palette_get(win, n, r, g, b) \
  1015. ((win)->vt->palette_get(win, n, r, g, b))
  1016. #define win_palette_set(win, n, r, g, b) \
  1017. ((win)->vt->palette_set(win, n, r, g, b))
  1018. #define win_palette_reset(win) \
  1019. ((win)->vt->palette_reset(win))
  1020. #define win_get_pos(win, x, y) \
  1021. ((win)->vt->get_pos(win, x, y))
  1022. #define win_get_pixels(win, x, y) \
  1023. ((win)->vt->get_pixels(win, x, y))
  1024. #define win_get_title(win, icon) \
  1025. ((win)->vt->get_title(win, icon))
  1026. #define win_is_utf8(win) \
  1027. ((win)->vt->is_utf8(win))
  1028. /*
  1029. * Global functions not specific to a connection instance.
  1030. */
  1031. void nonfatal(const char *, ...);
  1032. NORETURN void modalfatalbox(const char *, ...);
  1033. NORETURN void cleanup_exit(int);
  1034. /*
  1035. * Exports from conf.c, and a big enum (via parametric macro) of
  1036. * configuration option keys.
  1037. */
  1038. #define CONFIG_OPTIONS(X) \
  1039. /* X(value-type, subkey-type, keyword) */ \
  1040. X(STR, NONE, host) \
  1041. X(INT, NONE, port) \
  1042. X(INT, NONE, protocol) /* PROT_SSH, PROT_TELNET etc */ \
  1043. X(INT, NONE, addressfamily) /* ADDRTYPE_IPV[46] or ADDRTYPE_UNSPEC */ \
  1044. X(INT, NONE, close_on_exit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1045. X(BOOL, NONE, warn_on_close) \
  1046. X(INT, NONE, ping_interval) /* in seconds */ \
  1047. X(BOOL, NONE, tcp_nodelay) \
  1048. X(BOOL, NONE, tcp_keepalives) \
  1049. X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
  1050. /* Proxy options */ \
  1051. X(STR, NONE, proxy_exclude_list) \
  1052. X(INT, NONE, proxy_dns) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1053. X(BOOL, NONE, even_proxy_localhost) \
  1054. X(INT, NONE, proxy_type) /* PROXY_NONE, PROXY_SOCKS4, ... */ \
  1055. X(STR, NONE, proxy_host) \
  1056. X(INT, NONE, proxy_port) \
  1057. X(STR, NONE, proxy_username) \
  1058. X(STR, NONE, proxy_password) \
  1059. X(STR, NONE, proxy_telnet_command) \
  1060. X(INT, NONE, proxy_log_to_term) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1061. /* SSH options */ \
  1062. X(STR, NONE, remote_cmd) \
  1063. X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
  1064. X(BOOL, NONE, nopty) \
  1065. X(BOOL, NONE, compression) \
  1066. X(INT, INT, ssh_kexlist) \
  1067. X(INT, INT, ssh_hklist) \
  1068. X(INT, NONE, ssh_rekey_time) /* in minutes */ \
  1069. X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
  1070. X(BOOL, NONE, tryagent) \
  1071. X(BOOL, NONE, agentfwd) \
  1072. X(BOOL, NONE, change_username) /* allow username switching in SSH-2 */ \
  1073. X(INT, INT, ssh_cipherlist) \
  1074. X(FILENAME, NONE, keyfile) \
  1075. /* \
  1076. * Which SSH protocol to use. \
  1077. * For historical reasons, the current legal values for CONF_sshprot \
  1078. * are: \
  1079. * 0 = SSH-1 only \
  1080. * 3 = SSH-2 only \
  1081. * We used to also support \
  1082. * 1 = SSH-1 with fallback to SSH-2 \
  1083. * 2 = SSH-2 with fallback to SSH-1 \
  1084. * and we continue to use 0/3 in storage formats rather than the more \
  1085. * obvious 1/2 to avoid surprises if someone saves a session and later \
  1086. * downgrades PuTTY. So it's easier to use these numbers internally too. \
  1087. */ \
  1088. X(INT, NONE, sshprot) \
  1089. X(BOOL, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
  1090. X(BOOL, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
  1091. X(BOOL, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
  1092. X(BOOL, NONE, try_tis_auth) \
  1093. X(BOOL, NONE, try_ki_auth) \
  1094. X(BOOL, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
  1095. X(BOOL, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
  1096. X(BOOL, NONE, gssapifwd) /* forward tgt via gss */ \
  1097. X(INT, NONE, gssapirekey) /* KEXGSS refresh interval (mins) */ \
  1098. X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
  1099. X(FILENAME, NONE, ssh_gss_custom) \
  1100. X(BOOL, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
  1101. X(BOOL, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
  1102. X(BOOL, NONE, ssh_no_shell) /* avoid running a shell */ \
  1103. X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
  1104. X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
  1105. /* Telnet options */ \
  1106. X(STR, NONE, termtype) \
  1107. X(STR, NONE, termspeed) \
  1108. X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
  1109. X(STR, STR, environmt) \
  1110. X(STR, NONE, username) \
  1111. X(BOOL, NONE, username_from_env) \
  1112. X(STR, NONE, localusername) \
  1113. X(BOOL, NONE, rfc_environ) \
  1114. X(BOOL, NONE, passive_telnet) \
  1115. /* Serial port options */ \
  1116. X(STR, NONE, serline) \
  1117. X(INT, NONE, serspeed) \
  1118. X(INT, NONE, serdatabits) \
  1119. X(INT, NONE, serstopbits) \
  1120. X(INT, NONE, serparity) /* SER_PAR_NONE, SER_PAR_ODD, ... */ \
  1121. X(INT, NONE, serflow) /* SER_FLOW_NONE, SER_FLOW_XONXOFF, ... */ \
  1122. /* Keyboard options */ \
  1123. X(BOOL, NONE, bksp_is_delete) \
  1124. X(BOOL, NONE, rxvt_homeend) \
  1125. X(INT, NONE, funky_type) /* FUNKY_XTERM, FUNKY_LINUX, ... */ \
  1126. X(BOOL, NONE, no_applic_c) /* totally disable app cursor keys */ \
  1127. X(BOOL, NONE, no_applic_k) /* totally disable app keypad */ \
  1128. X(BOOL, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
  1129. X(BOOL, NONE, no_remote_resize) /* disable remote resizing */ \
  1130. X(BOOL, NONE, no_alt_screen) /* disable alternate screen */ \
  1131. X(BOOL, NONE, no_remote_wintitle) /* disable remote retitling */ \
  1132. X(BOOL, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
  1133. X(BOOL, NONE, no_dbackspace) /* disable destructive backspace */ \
  1134. X(BOOL, NONE, no_remote_charset) /* disable remote charset config */ \
  1135. X(INT, NONE, remote_qtitle_action) /* remote win title query action
  1136. * (TITLE_NONE, TITLE_EMPTY, ...) */ \
  1137. X(BOOL, NONE, app_cursor) \
  1138. X(BOOL, NONE, app_keypad) \
  1139. X(BOOL, NONE, nethack_keypad) \
  1140. X(BOOL, NONE, telnet_keyboard) \
  1141. X(BOOL, NONE, telnet_newline) \
  1142. X(BOOL, NONE, alt_f4) /* is it special? */ \
  1143. X(BOOL, NONE, alt_space) /* is it special? */ \
  1144. X(BOOL, NONE, alt_only) /* is it special? */ \
  1145. X(INT, NONE, localecho) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1146. X(INT, NONE, localedit) /* FORCE_ON, FORCE_OFF, AUTO */ \
  1147. X(BOOL, NONE, alwaysontop) \
  1148. X(BOOL, NONE, fullscreenonaltenter) \
  1149. X(BOOL, NONE, scroll_on_key) \
  1150. X(BOOL, NONE, scroll_on_disp) \
  1151. X(BOOL, NONE, erase_to_scrollback) \
  1152. X(BOOL, NONE, compose_key) \
  1153. X(BOOL, NONE, ctrlaltkeys) \
  1154. X(BOOL, NONE, osx_option_meta) \
  1155. X(BOOL, NONE, osx_command_meta) \
  1156. X(STR, NONE, wintitle) /* initial window title */ \
  1157. /* Terminal options */ \
  1158. X(INT, NONE, savelines) \
  1159. X(BOOL, NONE, dec_om) \
  1160. X(BOOL, NONE, wrap_mode) \
  1161. X(BOOL, NONE, lfhascr) \
  1162. X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
  1163. X(BOOL, NONE, blink_cur) \
  1164. X(INT, NONE, beep) /* BELL_DISABLED, BELL_DEFAULT, ... */ \
  1165. X(INT, NONE, beep_ind) /* B_IND_DISABLED, B_IND_FLASH, ... */ \
  1166. X(BOOL, NONE, bellovl) /* bell overload protection active? */ \
  1167. X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
  1168. X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
  1169. X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
  1170. X(FILENAME, NONE, bell_wavefile) \
  1171. X(BOOL, NONE, scrollbar) \
  1172. X(BOOL, NONE, scrollbar_in_fullscreen) \
  1173. X(INT, NONE, resize_action) /* RESIZE_TERM, RESIZE_DISABLED, ... */ \
  1174. X(BOOL, NONE, bce) \
  1175. X(BOOL, NONE, blinktext) \
  1176. X(BOOL, NONE, win_name_always) \
  1177. X(INT, NONE, width) \
  1178. X(INT, NONE, height) \
  1179. X(FONT, NONE, font) \
  1180. X(INT, NONE, font_quality) /* FQ_DEFAULT, FQ_ANTIALIASED, ... */ \
  1181. X(FILENAME, NONE, logfilename) \
  1182. X(INT, NONE, logtype) /* LGTYP_NONE, LGTYPE_ASCII, ... */ \
  1183. X(INT, NONE, logxfovr) /* LGXF_OVR, LGXF_APN, LGXF_ASK */ \
  1184. X(BOOL, NONE, logflush) \
  1185. X(BOOL, NONE, logheader) \
  1186. X(BOOL, NONE, logomitpass) \
  1187. X(BOOL, NONE, logomitdata) \
  1188. X(BOOL, NONE, hide_mouseptr) \
  1189. X(BOOL, NONE, sunken_edge) \
  1190. X(INT, NONE, window_border) /* in pixels */ \
  1191. X(STR, NONE, answerback) \
  1192. X(STR, NONE, printer) \
  1193. X(BOOL, NONE, arabicshaping) \
  1194. X(BOOL, NONE, bidi) \
  1195. /* Colour options */ \
  1196. X(BOOL, NONE, ansi_colour) \
  1197. X(BOOL, NONE, xterm_256_colour) \
  1198. X(BOOL, NONE, true_colour) \
  1199. X(BOOL, NONE, system_colour) \
  1200. X(BOOL, NONE, try_palette) \
  1201. X(INT, NONE, bold_style) /* 1=font 2=colour (3=both) */ \
  1202. X(INT, INT, colours) \
  1203. /* Selection options */ \
  1204. X(INT, NONE, mouse_is_xterm) /* 0=compromise 1=xterm 2=Windows */ \
  1205. X(BOOL, NONE, rect_select) \
  1206. X(BOOL, NONE, paste_controls) \
  1207. X(BOOL, NONE, rawcnp) \
  1208. X(BOOL, NONE, utf8linedraw) \
  1209. X(BOOL, NONE, rtf_paste) \
  1210. X(BOOL, NONE, mouse_override) \
  1211. X(INT, INT, wordness) \
  1212. X(BOOL, NONE, mouseautocopy) \
  1213. X(INT, NONE, mousepaste) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1214. X(INT, NONE, ctrlshiftins) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1215. X(INT, NONE, ctrlshiftcv) /* CLIPUI_IMPLICIT, CLIPUI_EXPLICIT, ... */ \
  1216. X(STR, NONE, mousepaste_custom) \
  1217. X(STR, NONE, ctrlshiftins_custom) \
  1218. X(STR, NONE, ctrlshiftcv_custom) \
  1219. /* translations */ \
  1220. X(INT, NONE, vtmode) /* VT_XWINDOWS, VT_OEMANSI, ... */ \
  1221. X(STR, NONE, line_codepage) \
  1222. X(BOOL, NONE, cjk_ambig_wide) \
  1223. X(BOOL, NONE, utf8_override) \
  1224. X(BOOL, NONE, xlat_capslockcyr) \
  1225. /* X11 forwarding */ \
  1226. X(BOOL, NONE, x11_forward) \
  1227. X(STR, NONE, x11_display) \
  1228. X(INT, NONE, x11_auth) /* X11_NO_AUTH, X11_MIT, X11_XDM */ \
  1229. X(FILENAME, NONE, xauthfile) \
  1230. /* port forwarding */ \
  1231. X(BOOL, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
  1232. X(BOOL, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
  1233. /* \
  1234. * Subkeys for 'portfwd' can have the following forms: \
  1235. * \
  1236. * [LR]localport \
  1237. * [LR]localaddr:localport \
  1238. * \
  1239. * Dynamic forwardings are indicated by an 'L' key, and the \
  1240. * special value "D". For all other forwardings, the value \
  1241. * should be of the form 'host:port'. \
  1242. */ \
  1243. X(STR, STR, portfwd) \
  1244. /* SSH bug compatibility modes. All FORCE_ON/FORCE_OFF/AUTO */ \
  1245. X(INT, NONE, sshbug_ignore1) \
  1246. X(INT, NONE, sshbug_plainpw1) \
  1247. X(INT, NONE, sshbug_rsa1) \
  1248. X(INT, NONE, sshbug_hmac2) \
  1249. X(INT, NONE, sshbug_derivekey2) \
  1250. X(INT, NONE, sshbug_rsapad2) \
  1251. X(INT, NONE, sshbug_pksessid2) \
  1252. X(INT, NONE, sshbug_rekey2) \
  1253. X(INT, NONE, sshbug_maxpkt2) \
  1254. X(INT, NONE, sshbug_ignore2) \
  1255. X(INT, NONE, sshbug_oldgex2) \
  1256. X(INT, NONE, sshbug_winadj) \
  1257. X(INT, NONE, sshbug_chanreq) \
  1258. /* \
  1259. * ssh_simple means that we promise never to open any channel \
  1260. * other than the main one, which means it can safely use a very \
  1261. * large window in SSH-2. \
  1262. */ \
  1263. X(BOOL, NONE, ssh_simple) \
  1264. X(BOOL, NONE, ssh_connection_sharing) \
  1265. X(BOOL, NONE, ssh_connection_sharing_upstream) \
  1266. X(BOOL, NONE, ssh_connection_sharing_downstream) \
  1267. /*
  1268. * ssh_manual_hostkeys is conceptually a set rather than a
  1269. * dictionary: the string subkeys are the important thing, and the
  1270. * actual values to which those subkeys map are all "".
  1271. */ \
  1272. X(STR, STR, ssh_manual_hostkeys) \
  1273. /* Options for pterm. Should split out into platform-dependent part. */ \
  1274. X(BOOL, NONE, stamp_utmp) \
  1275. X(BOOL, NONE, login_shell) \
  1276. X(BOOL, NONE, scrollbar_on_left) \
  1277. X(BOOL, NONE, shadowbold) \
  1278. X(FONT, NONE, boldfont) \
  1279. X(FONT, NONE, widefont) \
  1280. X(FONT, NONE, wideboldfont) \
  1281. X(INT, NONE, shadowboldoffset) /* in pixels */ \
  1282. X(BOOL, NONE, crhaslf) \
  1283. X(STR, NONE, winclass) \
  1284. /* end of list */
  1285. /* Now define the actual enum of option keywords using that macro. */
  1286. #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
  1287. enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
  1288. #undef CONF_ENUM_DEF
  1289. #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
  1290. /* Functions handling configuration structures. */
  1291. Conf *conf_new(void); /* create an empty configuration */
  1292. void conf_free(Conf *conf);
  1293. Conf *conf_copy(Conf *oldconf);
  1294. void conf_copy_into(Conf *dest, Conf *src);
  1295. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  1296. bool conf_get_bool(Conf *conf, int key);
  1297. int conf_get_int(Conf *conf, int key);
  1298. int conf_get_int_int(Conf *conf, int key, int subkey);
  1299. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  1300. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  1301. Filename *conf_get_filename(Conf *conf, int key);
  1302. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  1303. /* Optional accessor function: return NULL if key does not exist. */
  1304. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  1305. /* Accessor function to step through a string-subkeyed list.
  1306. * Returns the next subkey after the provided one, or the first if NULL.
  1307. * Returns NULL if there are none left.
  1308. * Both the return value and *subkeyout are still owned by conf. */
  1309. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  1310. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  1311. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  1312. /* Functions to set entries in configuration. Always copy their inputs. */
  1313. void conf_set_bool(Conf *conf, int key, bool value);
  1314. void conf_set_int(Conf *conf, int key, int value);
  1315. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  1316. void conf_set_str(Conf *conf, int key, const char *value);
  1317. void conf_set_str_str(Conf *conf, int key,
  1318. const char *subkey, const char *val);
  1319. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  1320. void conf_set_filename(Conf *conf, int key, const Filename *val);
  1321. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  1322. /* Serialisation functions for Duplicate Session */
  1323. void conf_serialise(BinarySink *bs, Conf *conf);
  1324. bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  1325. /*
  1326. * Functions to copy, free, serialise and deserialise FontSpecs.
  1327. * Provided per-platform, to go with the platform's idea of a
  1328. * FontSpec's contents.
  1329. *
  1330. * fontspec_serialise returns the number of bytes written, and can
  1331. * handle data==NULL without crashing. So you can call it once to find
  1332. * out a size, then again once you've allocated a buffer.
  1333. */
  1334. FontSpec *fontspec_copy(const FontSpec *f);
  1335. void fontspec_free(FontSpec *f);
  1336. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1337. FontSpec *fontspec_deserialise(BinarySource *src);
  1338. /*
  1339. * Exports from noise.c.
  1340. */
  1341. typedef enum NoiseSourceId {
  1342. NOISE_SOURCE_TIME,
  1343. NOISE_SOURCE_IOID,
  1344. NOISE_SOURCE_IOLEN,
  1345. NOISE_SOURCE_KEY,
  1346. NOISE_SOURCE_MOUSEBUTTON,
  1347. NOISE_SOURCE_MOUSEPOS,
  1348. NOISE_SOURCE_MEMINFO,
  1349. NOISE_SOURCE_STAT,
  1350. NOISE_SOURCE_RUSAGE,
  1351. NOISE_SOURCE_FGWINDOW,
  1352. NOISE_SOURCE_CAPTURE,
  1353. NOISE_SOURCE_CLIPBOARD,
  1354. NOISE_SOURCE_QUEUE,
  1355. NOISE_SOURCE_CURSORPOS,
  1356. NOISE_SOURCE_THREADTIME,
  1357. NOISE_SOURCE_PROCTIME,
  1358. NOISE_SOURCE_PERFCOUNT,
  1359. NOISE_MAX_SOURCES
  1360. } NoiseSourceId;
  1361. void noise_get_heavy(void (*func) (void *, int));
  1362. void noise_get_light(void (*func) (void *, int));
  1363. void noise_regular(void);
  1364. void noise_ultralight(NoiseSourceId id, unsigned long data);
  1365. void random_save_seed(void);
  1366. void random_destroy_seed(void);
  1367. /*
  1368. * Exports from settings.c.
  1369. */
  1370. const struct BackendVtable *backend_vt_from_name(const char *name);
  1371. const struct BackendVtable *backend_vt_from_proto(int proto);
  1372. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1373. char *save_settings(const char *section, Conf *conf);
  1374. void save_open_settings(settings_w *sesskey, Conf *conf);
  1375. void load_settings(const char *section, Conf *conf);
  1376. void load_open_settings(settings_r *sesskey, Conf *conf);
  1377. void get_sesslist(struct sesslist *, bool allocate);
  1378. void do_defaults(const char *, Conf *);
  1379. void registry_cleanup(void);
  1380. /*
  1381. * Functions used by settings.c to provide platform-specific
  1382. * default settings.
  1383. *
  1384. * (The integer one is expected to return `def' if it has no clear
  1385. * opinion of its own. This is because there's no integer value
  1386. * which I can reliably set aside to indicate `nil'. The string
  1387. * function is perfectly all right returning NULL, of course. The
  1388. * Filename and FontSpec functions are _not allowed_ to fail to
  1389. * return, since these defaults _must_ be per-platform.)
  1390. *
  1391. * The 'Filename *' returned by platform_default_filename, and the
  1392. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1393. * transferred to the caller, and must be freed.
  1394. */
  1395. char *platform_default_s(const char *name);
  1396. bool platform_default_b(const char *name, bool def);
  1397. int platform_default_i(const char *name, int def);
  1398. Filename *platform_default_filename(const char *name);
  1399. FontSpec *platform_default_fontspec(const char *name);
  1400. /*
  1401. * Exports from terminal.c.
  1402. */
  1403. Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
  1404. void term_free(Terminal *);
  1405. void term_size(Terminal *, int, int, int);
  1406. void term_paint(Terminal *, int, int, int, int, bool);
  1407. void term_scroll(Terminal *, int, int);
  1408. void term_scroll_to_selection(Terminal *, int);
  1409. void term_pwron(Terminal *, bool);
  1410. void term_clrsb(Terminal *);
  1411. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  1412. int, int, bool, bool, bool);
  1413. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  1414. unsigned int);
  1415. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  1416. void term_update(Terminal *);
  1417. void term_invalidate(Terminal *);
  1418. void term_blink(Terminal *, bool set_cursor);
  1419. void term_do_paste(Terminal *, const wchar_t *, int);
  1420. void term_nopaste(Terminal *);
  1421. bool term_ldisc(Terminal *, int option);
  1422. void term_copyall(Terminal *, const int *, int);
  1423. void term_reconfig(Terminal *, Conf *);
  1424. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  1425. void term_request_paste(Terminal *, int clipboard);
  1426. void term_seen_key_event(Terminal *);
  1427. int term_data(Terminal *, bool is_stderr, const void *data, int len);
  1428. void term_provide_backend(Terminal *term, Backend *backend);
  1429. void term_provide_logctx(Terminal *term, LogContext *logctx);
  1430. void term_set_focus(Terminal *term, bool has_focus);
  1431. char *term_get_ttymode(Terminal *term, const char *mode);
  1432. int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
  1433. typedef enum SmallKeypadKey {
  1434. SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,
  1435. } SmallKeypadKey;
  1436. int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl);
  1437. int format_function_key(char *buf, Terminal *term, int key_number,
  1438. bool shift, bool ctrl);
  1439. int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key);
  1440. int format_numeric_keypad_key(char *buf, Terminal *term, char key,
  1441. bool shift, bool ctrl);
  1442. /*
  1443. * Exports from logging.c.
  1444. */
  1445. struct LogPolicyVtable {
  1446. /*
  1447. * Pass Event Log entries on from LogContext to the front end,
  1448. * which might write them to standard error or save them for a GUI
  1449. * list box or other things.
  1450. */
  1451. void (*eventlog)(LogPolicy *lp, const char *event);
  1452. /*
  1453. * Ask what to do about the specified output log file already
  1454. * existing. Can return four values:
  1455. *
  1456. * - 2 means overwrite the log file
  1457. * - 1 means append to the log file
  1458. * - 0 means cancel logging for this session
  1459. * - -1 means please wait, and callback() will be called with one
  1460. * of those options.
  1461. */
  1462. int (*askappend)(LogPolicy *lp, Filename *filename,
  1463. void (*callback)(void *ctx, int result), void *ctx);
  1464. /*
  1465. * Emergency logging when the log file itself can't be opened,
  1466. * which typically means we want to shout about it more loudly
  1467. * than a mere Event Log entry.
  1468. *
  1469. * One reasonable option is to send it to the same place that
  1470. * stderr output from the main session goes (so, either a console
  1471. * tool's actual stderr, or a terminal window). In many cases this
  1472. * is unlikely to cause this error message to turn up
  1473. * embarrassingly in a log file of real server output, because the
  1474. * whole point is that we haven't managed to open any such log
  1475. * file :-)
  1476. */
  1477. void (*logging_error)(LogPolicy *lp, const char *event);
  1478. };
  1479. struct LogPolicy {
  1480. const LogPolicyVtable *vt;
  1481. };
  1482. #define lp_eventlog(lp, event) ((lp)->vt->eventlog(lp, event))
  1483. #define lp_askappend(lp, fn, cb, ctx) ((lp)->vt->askappend(lp, fn, cb, ctx))
  1484. #define lp_logging_error(lp, event) ((lp)->vt->logging_error(lp, event))
  1485. LogContext *log_init(LogPolicy *lp, Conf *conf);
  1486. void log_free(LogContext *logctx);
  1487. void log_reconfig(LogContext *logctx, Conf *conf);
  1488. void logfopen(LogContext *logctx);
  1489. void logfclose(LogContext *logctx);
  1490. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  1491. void logflush(LogContext *logctx);
  1492. void logevent(LogContext *logctx, const char *event);
  1493. void logeventf(LogContext *logctx, const char *fmt, ...);
  1494. void logeventvf(LogContext *logctx, const char *fmt, va_list ap);
  1495. /*
  1496. * Pass a dynamically allocated string to logevent and immediately
  1497. * free it. Intended for use by wrapper macros which pass the return
  1498. * value of dupprintf straight to this.
  1499. */
  1500. void logevent_and_free(LogContext *logctx, char *event);
  1501. enum { PKT_INCOMING, PKT_OUTGOING };
  1502. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  1503. struct logblank_t {
  1504. int offset;
  1505. int len;
  1506. int type;
  1507. };
  1508. void log_packet(LogContext *logctx, int direction, int type,
  1509. const char *texttype, const void *data, int len,
  1510. int n_blanks, const struct logblank_t *blanks,
  1511. const unsigned long *sequence,
  1512. unsigned downstream_id, const char *additional_log_text);
  1513. /* This is defined by applications that have an obvious logging
  1514. * destination like standard error or the GUI. */
  1515. extern LogPolicy default_logpolicy[1];
  1516. /*
  1517. * Exports from testback.c
  1518. */
  1519. extern const struct BackendVtable null_backend;
  1520. extern const struct BackendVtable loop_backend;
  1521. /*
  1522. * Exports from raw.c.
  1523. */
  1524. extern const struct BackendVtable raw_backend;
  1525. /*
  1526. * Exports from rlogin.c.
  1527. */
  1528. extern const struct BackendVtable rlogin_backend;
  1529. /*
  1530. * Exports from telnet.c.
  1531. */
  1532. extern const struct BackendVtable telnet_backend;
  1533. /*
  1534. * Exports from ssh.c.
  1535. */
  1536. extern const struct BackendVtable ssh_backend;
  1537. /*
  1538. * Exports from ldisc.c.
  1539. */
  1540. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
  1541. void ldisc_configure(Ldisc *, Conf *);
  1542. void ldisc_free(Ldisc *);
  1543. void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
  1544. void ldisc_echoedit_update(Ldisc *);
  1545. /*
  1546. * Exports from ldiscucs.c.
  1547. */
  1548. void lpage_send(Ldisc *, int codepage, const char *buf, int len,
  1549. bool interactive);
  1550. void luni_send(Ldisc *, const wchar_t * widebuf, int len, bool interactive);
  1551. /*
  1552. * Exports from sshrand.c.
  1553. */
  1554. void random_add_noise(NoiseSourceId source, const void *noise, int length);
  1555. void random_read(void *buf, size_t size);
  1556. void random_get_savedata(void **data, int *len);
  1557. extern int random_active;
  1558. /* The random number subsystem is activated if at least one other entity
  1559. * within the program expresses an interest in it. So each SSH session
  1560. * calls random_ref on startup and random_unref on shutdown. */
  1561. void random_ref(void);
  1562. void random_unref(void);
  1563. /* random_setup_special is used by PuTTYgen. It makes an extra-big
  1564. * random number generator. */
  1565. void random_setup_special();
  1566. /* Manually drop a random seed into the random number generator, e.g.
  1567. * just before generating a key. */
  1568. void random_reseed(ptrlen seed);
  1569. /*
  1570. * Exports from pinger.c.
  1571. */
  1572. typedef struct Pinger Pinger;
  1573. Pinger *pinger_new(Conf *conf, Backend *backend);
  1574. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  1575. void pinger_free(Pinger *);
  1576. /*
  1577. * Exports from misc.c.
  1578. */
  1579. #include "misc.h"
  1580. bool conf_launchable(Conf *conf);
  1581. char const *conf_dest(Conf *conf);
  1582. /*
  1583. * Exports from sessprep.c.
  1584. */
  1585. void prepare_session(Conf *conf);
  1586. /*
  1587. * Exports from sercfg.c.
  1588. */
  1589. void ser_setup_config_box(struct controlbox *b, bool midsession,
  1590. int parity_mask, int flow_mask);
  1591. /*
  1592. * Exports from version.c.
  1593. */
  1594. extern const char ver[];
  1595. extern const char commitid[];
  1596. /*
  1597. * Exports from unicode.c.
  1598. */
  1599. #ifndef CP_UTF8
  1600. #define CP_UTF8 65001
  1601. #endif
  1602. /* void init_ucs(void); -- this is now in platform-specific headers */
  1603. bool is_dbcs_leadbyte(int codepage, char byte);
  1604. int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
  1605. wchar_t *wcstr, int wclen);
  1606. int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
  1607. char *mbstr, int mblen, const char *defchr,
  1608. struct unicode_data *ucsdata);
  1609. wchar_t xlat_uskbd2cyrllic(int ch);
  1610. int check_compose(int first, int second);
  1611. int decode_codepage(char *cp_name);
  1612. const char *cp_enumerate (int index);
  1613. const char *cp_name(int codepage);
  1614. void get_unitab(int codepage, wchar_t * unitab, int ftype);
  1615. /*
  1616. * Exports from wcwidth.c
  1617. */
  1618. int mk_wcwidth(unsigned int ucs);
  1619. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  1620. int mk_wcwidth_cjk(unsigned int ucs);
  1621. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  1622. /*
  1623. * Exports from pageantc.c.
  1624. *
  1625. * agent_query returns NULL for here's-a-response, and non-NULL for
  1626. * query-in- progress. In the latter case there will be a call to
  1627. * `callback' at some future point, passing callback_ctx as the first
  1628. * parameter and the actual reply data as the second and third.
  1629. *
  1630. * The response may be a NULL pointer (in either of the synchronous
  1631. * or asynchronous cases), which indicates failure to receive a
  1632. * response.
  1633. *
  1634. * When the return from agent_query is not NULL, it identifies the
  1635. * in-progress query in case it needs to be cancelled. If
  1636. * agent_cancel_query is called, then the pending query is destroyed
  1637. * and the callback will not be called. (E.g. if you're going to throw
  1638. * away the thing you were using as callback_ctx.)
  1639. *
  1640. * Passing a null pointer as callback forces agent_query to behave
  1641. * synchronously, i.e. it will block if necessary, and guarantee to
  1642. * return NULL. The wrapper function agent_query_synchronous() makes
  1643. * this easier.
  1644. */
  1645. typedef struct agent_pending_query agent_pending_query;
  1646. agent_pending_query *agent_query(
  1647. strbuf *in, void **out, int *outlen,
  1648. void (*callback)(void *, void *, int), void *callback_ctx);
  1649. void agent_cancel_query(agent_pending_query *);
  1650. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  1651. bool agent_exists(void);
  1652. /*
  1653. * Exports from wildcard.c
  1654. */
  1655. const char *wc_error(int value);
  1656. int wc_match_pl(const char *wildcard, ptrlen target);
  1657. int wc_match(const char *wildcard, const char *target);
  1658. bool wc_unescape(char *output, const char *wildcard);
  1659. /*
  1660. * Exports from frontend (windlg.c etc)
  1661. */
  1662. void pgp_fingerprints(void);
  1663. /*
  1664. * have_ssh_host_key() just returns true if a key of that type is
  1665. * already cached and false otherwise.
  1666. */
  1667. bool have_ssh_host_key(const char *host, int port, const char *keytype);
  1668. /*
  1669. * Exports from console frontends (wincons.c, uxcons.c)
  1670. * that aren't equivalents to things in windlg.c et al.
  1671. */
  1672. extern bool console_batch_mode;
  1673. int console_get_userpass_input(prompts_t *p);
  1674. bool is_interactive(void);
  1675. void console_print_error_msg(const char *prefix, const char *msg);
  1676. void console_print_error_msg_fmt_v(
  1677. const char *prefix, const char *fmt, va_list ap);
  1678. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...);
  1679. /*
  1680. * Exports from printing.c.
  1681. */
  1682. typedef struct printer_enum_tag printer_enum;
  1683. typedef struct printer_job_tag printer_job;
  1684. printer_enum *printer_start_enum(int *nprinters);
  1685. char *printer_get_name(printer_enum *, int);
  1686. void printer_finish_enum(printer_enum *);
  1687. printer_job *printer_start_job(char *printer);
  1688. void printer_job_data(printer_job *, void *, int);
  1689. void printer_finish_job(printer_job *);
  1690. /*
  1691. * Exports from cmdline.c (and also cmdline_error(), which is
  1692. * defined differently in various places and required _by_
  1693. * cmdline.c).
  1694. *
  1695. * Note that cmdline_process_param takes a const option string, but a
  1696. * writable argument string. That's not a mistake - that's so it can
  1697. * zero out password arguments in the hope of not having them show up
  1698. * avoidably in Unix 'ps'.
  1699. */
  1700. int cmdline_process_param(const char *, char *, int, Conf *);
  1701. void cmdline_run_saved(Conf *);
  1702. void cmdline_cleanup(void);
  1703. int cmdline_get_passwd_input(prompts_t *p);
  1704. bool cmdline_host_ok(Conf *);
  1705. #define TOOLTYPE_FILETRANSFER 1
  1706. #define TOOLTYPE_NONNETWORK 2
  1707. #define TOOLTYPE_HOST_ARG 4
  1708. #define TOOLTYPE_HOST_ARG_CAN_BE_SESSION 8
  1709. #define TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX 16
  1710. #define TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD 32
  1711. #define TOOLTYPE_PORT_ARG 64
  1712. extern int cmdline_tooltype;
  1713. void cmdline_error(const char *, ...);
  1714. /*
  1715. * Exports from config.c.
  1716. */
  1717. struct controlbox;
  1718. union control;
  1719. void conf_radiobutton_handler(union control *ctrl, dlgparam *dlg,
  1720. void *data, int event);
  1721. #define CHECKBOX_INVERT (1<<30)
  1722. void conf_checkbox_handler(union control *ctrl, dlgparam *dlg,
  1723. void *data, int event);
  1724. void conf_editbox_handler(union control *ctrl, dlgparam *dlg,
  1725. void *data, int event);
  1726. void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
  1727. void *data, int event);
  1728. void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
  1729. void *data, int event);
  1730. /* Much more special-purpose function needed by sercfg.c */
  1731. void config_protocolbuttons_handler(union control *, dlgparam *, void *, int);
  1732. void setup_config_box(struct controlbox *b, bool midsession,
  1733. int protocol, int protcfginfo);
  1734. /*
  1735. * Exports from minibidi.c.
  1736. */
  1737. typedef struct bidi_char {
  1738. unsigned int origwc, wc;
  1739. unsigned short index;
  1740. } bidi_char;
  1741. int do_bidi(bidi_char *line, int count);
  1742. int do_shape(bidi_char *line, bidi_char *to, int count);
  1743. bool is_rtl(int c);
  1744. /*
  1745. * X11 auth mechanisms we know about.
  1746. */
  1747. enum {
  1748. X11_NO_AUTH,
  1749. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  1750. X11_XDM, /* XDM-AUTHORIZATION-1 */
  1751. X11_NAUTHS
  1752. };
  1753. extern const char *const x11_authnames[]; /* declared in x11fwd.c */
  1754. /*
  1755. * An enum for the copy-paste UI action configuration.
  1756. */
  1757. enum {
  1758. CLIPUI_NONE, /* UI action has no copy/paste effect */
  1759. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  1760. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  1761. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  1762. };
  1763. /*
  1764. * Miscellaneous exports from the platform-specific code.
  1765. *
  1766. * filename_serialise and filename_deserialise have the same semantics
  1767. * as fontspec_serialise and fontspec_deserialise above.
  1768. */
  1769. Filename *filename_from_str(const char *string);
  1770. const char *filename_to_str(const Filename *fn);
  1771. bool filename_equal(const Filename *f1, const Filename *f2);
  1772. bool filename_is_null(const Filename *fn);
  1773. Filename *filename_copy(const Filename *fn);
  1774. void filename_free(Filename *fn);
  1775. void filename_serialise(BinarySink *bs, const Filename *f);
  1776. Filename *filename_deserialise(BinarySource *src);
  1777. char *get_username(void); /* return value needs freeing */
  1778. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  1779. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  1780. bool open_for_write_would_lose_data(const Filename *fn);
  1781. /*
  1782. * Exports and imports from timing.c.
  1783. *
  1784. * schedule_timer() asks the front end to schedule a callback to a
  1785. * timer function in a given number of ticks. The returned value is
  1786. * the time (in ticks since an arbitrary offset) at which the
  1787. * callback can be expected. This value will also be passed as the
  1788. * `now' parameter to the callback function. Hence, you can (for
  1789. * example) schedule an event at a particular time by calling
  1790. * schedule_timer() and storing the return value in your context
  1791. * structure as the time when that event is due. The first time a
  1792. * callback function gives you that value or more as `now', you do
  1793. * the thing.
  1794. *
  1795. * expire_timer_context() drops all current timers associated with
  1796. * a given value of ctx (for when you're about to free ctx).
  1797. *
  1798. * run_timers() is called from the front end when it has reason to
  1799. * think some timers have reached their moment, or when it simply
  1800. * needs to know how long to wait next. We pass it the time we
  1801. * think it is. It returns true and places the time when the next
  1802. * timer needs to go off in `next', or alternatively it returns
  1803. * false if there are no timers at all pending.
  1804. *
  1805. * timer_change_notify() must be supplied by the front end; it
  1806. * notifies the front end that a new timer has been added to the
  1807. * list which is sooner than any existing ones. It provides the
  1808. * time when that timer needs to go off.
  1809. *
  1810. * *** FRONT END IMPLEMENTORS NOTE:
  1811. *
  1812. * There's an important subtlety in the front-end implementation of
  1813. * the timer interface. When a front end is given a `next' value,
  1814. * either returned from run_timers() or via timer_change_notify(),
  1815. * it should ensure that it really passes _that value_ as the `now'
  1816. * parameter to its next run_timers call. It should _not_ simply
  1817. * call GETTICKCOUNT() to get the `now' parameter when invoking
  1818. * run_timers().
  1819. *
  1820. * The reason for this is that an OS's system clock might not agree
  1821. * exactly with the timing mechanisms it supplies to wait for a
  1822. * given interval. I'll illustrate this by the simple example of
  1823. * Unix Plink, which uses timeouts to select() in a way which for
  1824. * these purposes can simply be considered to be a wait() function.
  1825. * Suppose, for the sake of argument, that this wait() function
  1826. * tends to return early by 1%. Then a possible sequence of actions
  1827. * is:
  1828. *
  1829. * - run_timers() tells the front end that the next timer firing
  1830. * is 10000ms from now.
  1831. * - Front end calls wait(10000ms), but according to
  1832. * GETTICKCOUNT() it has only waited for 9900ms.
  1833. * - Front end calls run_timers() again, passing time T-100ms as
  1834. * `now'.
  1835. * - run_timers() does nothing, and says the next timer firing is
  1836. * still 100ms from now.
  1837. * - Front end calls wait(100ms), which only waits for 99ms.
  1838. * - Front end calls run_timers() yet again, passing time T-1ms.
  1839. * - run_timers() says there's still 1ms to wait.
  1840. * - Front end calls wait(1ms).
  1841. *
  1842. * If you're _lucky_ at this point, wait(1ms) will actually wait
  1843. * for 1ms and you'll only have woken the program up three times.
  1844. * If you're unlucky, wait(1ms) might do nothing at all due to
  1845. * being below some minimum threshold, and you might find your
  1846. * program spends the whole of the last millisecond tight-looping
  1847. * between wait() and run_timers().
  1848. *
  1849. * Instead, what you should do is to _save_ the precise `next'
  1850. * value provided by run_timers() or via timer_change_notify(), and
  1851. * use that precise value as the input to the next run_timers()
  1852. * call. So:
  1853. *
  1854. * - run_timers() tells the front end that the next timer firing
  1855. * is at time T, 10000ms from now.
  1856. * - Front end calls wait(10000ms).
  1857. * - Front end then immediately calls run_timers() and passes it
  1858. * time T, without stopping to check GETTICKCOUNT() at all.
  1859. *
  1860. * This guarantees that the program wakes up only as many times as
  1861. * there are actual timer actions to be taken, and that the timing
  1862. * mechanism will never send it into a tight loop.
  1863. *
  1864. * (It does also mean that the timer action in the above example
  1865. * will occur 100ms early, but this is not generally critical. And
  1866. * the hypothetical 1% error in wait() will be partially corrected
  1867. * for anyway when, _after_ run_timers() returns, you call
  1868. * GETTICKCOUNT() and compare the result with the returned `next'
  1869. * value to find out how long you have to make your next wait().)
  1870. */
  1871. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  1872. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  1873. void expire_timer_context(void *ctx);
  1874. bool run_timers(unsigned long now, unsigned long *next);
  1875. void timer_change_notify(unsigned long next);
  1876. unsigned long timing_last_clock(void);
  1877. /*
  1878. * Exports from callback.c.
  1879. *
  1880. * This provides a method of queuing function calls to be run at the
  1881. * earliest convenience from the top-level event loop. Use it if
  1882. * you're deep in a nested chain of calls and want to trigger an
  1883. * action which will probably lead to your function being re-entered
  1884. * recursively if you just call the initiating function the normal
  1885. * way.
  1886. *
  1887. * Most front ends run the queued callbacks by simply calling
  1888. * run_toplevel_callbacks() after handling each event in their
  1889. * top-level event loop. However, if a front end doesn't have control
  1890. * over its own event loop (e.g. because it's using GTK) then it can
  1891. * instead request notifications when a callback is available, so that
  1892. * it knows to ask its delegate event loop to do the same thing. Also,
  1893. * if a front end needs to know whether a callback is pending without
  1894. * actually running it (e.g. so as to put a zero timeout on a select()
  1895. * call) then it can call toplevel_callback_pending(), which will
  1896. * return true if at least one callback is in the queue.
  1897. *
  1898. * run_toplevel_callbacks() returns true if it ran any actual code.
  1899. * This can be used as a means of speculatively terminating a select
  1900. * loop, as in PSFTP, for example - if a callback has run then perhaps
  1901. * it might have done whatever the loop's caller was waiting for.
  1902. */
  1903. typedef void (*toplevel_callback_fn_t)(void *ctx);
  1904. void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
  1905. bool run_toplevel_callbacks(void);
  1906. bool toplevel_callback_pending(void);
  1907. void delete_callbacks_for_context(void *ctx);
  1908. /*
  1909. * Another facility in callback.c deals with 'idempotent' callbacks,
  1910. * defined as those which never need to be scheduled again if they are
  1911. * already scheduled and have not yet run. (An example would be one
  1912. * which, when called, empties a queue of data completely: when data
  1913. * is added to the queue, you must ensure a run of the queue-consuming
  1914. * function has been scheduled, but if one is already pending, you
  1915. * don't need to schedule a second one.)
  1916. */
  1917. struct IdempotentCallback {
  1918. toplevel_callback_fn_t fn;
  1919. void *ctx;
  1920. bool queued;
  1921. };
  1922. void queue_idempotent_callback(struct IdempotentCallback *ic);
  1923. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  1924. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  1925. void *ctx);
  1926. /*
  1927. * Define no-op macros for the jump list functions, on platforms that
  1928. * don't support them. (This is a bit of a hack, and it'd be nicer to
  1929. * localise even the calls to those functions into the Windows front
  1930. * end, but it'll do for the moment.)
  1931. */
  1932. #ifndef JUMPLIST_SUPPORTED
  1933. #define add_session_to_jumplist(x) ((void)0)
  1934. #define remove_session_from_jumplist(x) ((void)0)
  1935. #endif
  1936. /* SURROGATE PAIR */
  1937. #define HIGH_SURROGATE_START 0xd800
  1938. #define HIGH_SURROGATE_END 0xdbff
  1939. #define LOW_SURROGATE_START 0xdc00
  1940. #define LOW_SURROGATE_END 0xdfff
  1941. /* These macros exist in the Windows API, so the environment may
  1942. * provide them. If not, define them in terms of the above. */
  1943. #ifndef IS_HIGH_SURROGATE
  1944. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1945. ((wch) <= HIGH_SURROGATE_END))
  1946. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  1947. ((wch) <= LOW_SURROGATE_END))
  1948. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  1949. IS_LOW_SURROGATE(ls))
  1950. #endif
  1951. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1952. ((wch) <= LOW_SURROGATE_END))
  1953. #define HIGH_SURROGATE_OF(codept) \
  1954. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  1955. #define LOW_SURROGATE_OF(codept) \
  1956. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  1957. #define FROM_SURROGATES(wch1, wch2) \
  1958. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  1959. #endif