putty.h 65 KB

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