putty.h 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  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. LogContext *logctx, Conf *conf,
  425. const char *host, int port,
  426. char **realhost, int nodelay, int keepalive);
  427. void (*free) (Backend *be);
  428. /* Pass in a replacement configuration. */
  429. void (*reconfig) (Backend *be, Conf *conf);
  430. /* send() returns the current amount of buffered data. */
  431. int (*send) (Backend *be, const char *buf, int len);
  432. /* sendbuffer() does the same thing but without attempting a send */
  433. int (*sendbuffer) (Backend *be);
  434. void (*size) (Backend *be, int width, int height);
  435. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  436. const SessionSpecial *(*get_specials) (Backend *be);
  437. int (*connected) (Backend *be);
  438. int (*exitcode) (Backend *be);
  439. /* If back->sendok() returns FALSE, the backend doesn't currently
  440. * want input data, so the frontend should avoid acquiring any if
  441. * possible (passing back-pressure on to its sender). */
  442. int (*sendok) (Backend *be);
  443. int (*ldisc_option_state) (Backend *be, int);
  444. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  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, logctx, conf, host, port, rhost, nd, ka) \
  456. ((vt)->init(fe, out, logctx, 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_unthrottle(be, bufsize) ((be)->vt->unthrottle(be, bufsize))
  471. #define backend_cfg_info(be) ((be)->vt->cfg_info(be))
  472. extern const struct BackendVtable *const backends[];
  473. /*
  474. * Suggested default protocol provided by the backend link module.
  475. * The application is free to ignore this.
  476. */
  477. extern const int be_default_protocol;
  478. /*
  479. * Name of this particular application, for use in the config box
  480. * and other pieces of text.
  481. */
  482. extern const char *const appname;
  483. /*
  484. * Some global flags denoting the type of application.
  485. *
  486. * FLAG_VERBOSE is set when the user requests verbose details.
  487. *
  488. * FLAG_INTERACTIVE is set when a full interactive shell session is
  489. * being run, _either_ because no remote command has been provided
  490. * _or_ because the application is GUI and can't run non-
  491. * interactively.
  492. *
  493. * These flags describe the type of _application_ - they wouldn't
  494. * vary between individual sessions - and so it's OK to have this
  495. * variable be GLOBAL.
  496. *
  497. * Note that additional flags may be defined in platform-specific
  498. * headers. It's probably best if those ones start from 0x1000, to
  499. * avoid collision.
  500. */
  501. #define FLAG_VERBOSE 0x0001
  502. #define FLAG_INTERACTIVE 0x0002
  503. GLOBAL int flags;
  504. /*
  505. * Likewise, these two variables are set up when the application
  506. * initialises, and inform all default-settings accesses after
  507. * that.
  508. */
  509. GLOBAL int default_protocol;
  510. GLOBAL int default_port;
  511. /*
  512. * This is set TRUE by cmdline.c iff a session is loaded with "-load".
  513. */
  514. GLOBAL int loaded_session;
  515. /*
  516. * This is set to the name of the loaded session.
  517. */
  518. GLOBAL char *cmdline_session_name;
  519. /*
  520. * Mechanism for getting text strings such as usernames and passwords
  521. * from the front-end.
  522. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  523. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  524. *
  525. * Since many of the pieces of text involved may be chosen by the server,
  526. * the caller must take care to ensure that the server can't spoof locally-
  527. * generated prompts such as key passphrase prompts. Some ground rules:
  528. * - If the front-end needs to truncate a string, it should lop off the
  529. * end.
  530. * - The front-end should filter out any dangerous characters and
  531. * generally not trust the strings. (But \n is required to behave
  532. * vaguely sensibly, at least in `instruction', and ideally in
  533. * `prompt[]' too.)
  534. */
  535. typedef struct {
  536. char *prompt;
  537. int echo;
  538. /*
  539. * 'result' must be a dynamically allocated array of exactly
  540. * 'resultsize' chars. The code for actually reading input may
  541. * realloc it bigger (and adjust resultsize accordingly) if it has
  542. * to. The caller should free it again when finished with it.
  543. *
  544. * If resultsize==0, then result may be NULL. When setting up a
  545. * prompt_t, it's therefore easiest to initialise them this way,
  546. * which means all actual allocation is done by the callee. This
  547. * is what add_prompt does.
  548. */
  549. char *result;
  550. size_t resultsize;
  551. } prompt_t;
  552. typedef struct {
  553. /*
  554. * Indicates whether the information entered is to be used locally
  555. * (for instance a key passphrase prompt), or is destined for the wire.
  556. * This is a hint only; the front-end is at liberty not to use this
  557. * information (so the caller should ensure that the supplied text is
  558. * sufficient).
  559. */
  560. int to_server;
  561. char *name; /* Short description, perhaps for dialog box title */
  562. int name_reqd; /* Display of `name' required or optional? */
  563. char *instruction; /* Long description, maybe with embedded newlines */
  564. int instr_reqd; /* Display of `instruction' required or optional? */
  565. size_t n_prompts; /* May be zero (in which case display the foregoing,
  566. * if any, and return success) */
  567. prompt_t **prompts;
  568. Frontend *frontend;
  569. void *data; /* slot for housekeeping data, managed by
  570. * get_userpass_input(); initially NULL */
  571. } prompts_t;
  572. prompts_t *new_prompts(Frontend *frontend);
  573. void add_prompt(prompts_t *p, char *promptstr, int echo);
  574. void prompt_set_result(prompt_t *pr, const char *newstr);
  575. void prompt_ensure_result_size(prompt_t *pr, int len);
  576. /* Burn the evidence. (Assumes _all_ strings want free()ing.) */
  577. void free_prompts(prompts_t *p);
  578. /*
  579. * Data type definitions for true-colour terminal display.
  580. * 'optionalrgb' describes a single RGB colour, which overrides the
  581. * other colour settings if 'enabled' is nonzero, and is ignored
  582. * otherwise. 'truecolour' contains a pair of those for foreground and
  583. * background.
  584. */
  585. typedef struct optionalrgb {
  586. unsigned char enabled;
  587. unsigned char r, g, b;
  588. } optionalrgb;
  589. extern const optionalrgb optionalrgb_none;
  590. typedef struct truecolour {
  591. optionalrgb fg, bg;
  592. } truecolour;
  593. #define optionalrgb_equal(r1,r2) ( \
  594. (r1).enabled==(r2).enabled && \
  595. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  596. #define truecolour_equal(c1,c2) ( \
  597. optionalrgb_equal((c1).fg, (c2).fg) && \
  598. optionalrgb_equal((c1).bg, (c2).bg))
  599. /*
  600. * Enumeration of clipboards. We provide some standard ones cross-
  601. * platform, and then permit each platform to extend this enumeration
  602. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  603. *
  604. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  605. * from which return no data.
  606. *
  607. * CLIP_LOCAL refers to a buffer within terminal.c, which
  608. * unconditionally saves the last data selected in the terminal. In
  609. * configurations where a system clipboard is not written
  610. * automatically on selection but instead by an explicit UI action,
  611. * this is where the code responding to that action can find the data
  612. * to write to the clipboard in question.
  613. */
  614. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  615. X(CLIP_NULL, "null clipboard") \
  616. X(CLIP_LOCAL, "last text selected in terminal") \
  617. /* end of list */
  618. #define ALL_CLIPBOARDS(X) \
  619. CROSS_PLATFORM_CLIPBOARDS(X) \
  620. PLATFORM_CLIPBOARDS(X) \
  621. /* end of list */
  622. #define CLIP_ID(id,name) id,
  623. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  624. #undef CLIP_ID
  625. /*
  626. * Exports from the front end.
  627. */
  628. void request_resize(Frontend *frontend, int, int);
  629. void do_text(Context, int, int, wchar_t *, int, unsigned long, int,
  630. truecolour);
  631. void do_cursor(Context, int, int, wchar_t *, int, unsigned long, int,
  632. truecolour);
  633. int char_width(Context ctx, int uc);
  634. #ifdef OPTIMISE_SCROLL
  635. void do_scroll(Context, int, int, int);
  636. #endif
  637. void set_title(Frontend *frontend, char *);
  638. void set_icon(Frontend *frontend, char *);
  639. void set_sbar(Frontend *frontend, int, int, int);
  640. Context get_ctx(Frontend *frontend);
  641. void free_ctx(Context);
  642. void palette_set(Frontend *frontend, int, int, int, int);
  643. void palette_reset(Frontend *frontend);
  644. int palette_get(Frontend *frontend, int n, int *r, int *g, int *b);
  645. void write_clip(Frontend *frontend, int clipboard, wchar_t *, int *,
  646. truecolour *, int, int);
  647. void optimised_move(Frontend *frontend, int, int, int);
  648. void set_raw_mouse_mode(Frontend *frontend, int);
  649. void connection_fatal(Frontend *frontend, const char *, ...);
  650. void nonfatal(const char *, ...);
  651. void modalfatalbox(const char *, ...);
  652. #ifdef macintosh
  653. #pragma noreturn(modalfatalbox)
  654. #endif
  655. void do_beep(Frontend *frontend, int);
  656. void sys_cursor(Frontend *frontend, int x, int y);
  657. void frontend_request_paste(Frontend *frontend, int clipboard);
  658. void frontend_echoedit_update(Frontend *frontend, int echo, int edit);
  659. /* It's the backend's responsibility to invoke this at the start of a
  660. * connection, if necessary; it can also invoke it later if the set of
  661. * special commands changes. It does not need to invoke it at session
  662. * shutdown. */
  663. void update_specials_menu(Frontend *frontend);
  664. int from_backend(Frontend *frontend, int is_stderr, const void *data, int len);
  665. /* Called when the back end wants to indicate that EOF has arrived on
  666. * the server-to-client stream. Returns FALSE to indicate that we
  667. * intend to keep the session open in the other direction, or TRUE to
  668. * indicate that if they're closing so are we. */
  669. int from_backend_eof(Frontend *frontend);
  670. void notify_remote_exit(Frontend *frontend);
  671. /* Get a sensible value for a tty mode. NULL return = don't set.
  672. * Otherwise, returned value should be freed by caller. */
  673. char *get_ttymode(Frontend *frontend, const char *mode);
  674. /*
  675. * >0 = `got all results, carry on'
  676. * 0 = `user cancelled' (FIXME distinguish "give up entirely" and "next auth"?)
  677. * <0 = `please call back later with a fuller bufchain'
  678. */
  679. int get_userpass_input(prompts_t *p, bufchain *input);
  680. #define OPTIMISE_IS_SCROLL 1
  681. void set_iconic(Frontend *frontend, int iconic);
  682. void move_window(Frontend *frontend, int x, int y);
  683. void set_zorder(Frontend *frontend, int top);
  684. void refresh_window(Frontend *frontend);
  685. void set_zoomed(Frontend *frontend, int zoomed);
  686. int is_iconic(Frontend *frontend);
  687. void get_window_pos(Frontend *frontend, int *x, int *y);
  688. void get_window_pixels(Frontend *frontend, int *x, int *y);
  689. char *get_window_title(Frontend *frontend, int icon);
  690. /* Hint from backend to frontend about time-consuming operations.
  691. * Initial state is assumed to be BUSY_NOT. */
  692. enum {
  693. BUSY_NOT, /* Not busy, all user interaction OK */
  694. BUSY_WAITING, /* Waiting for something; local event loops still running
  695. so some local interaction (e.g. menus) OK, but network
  696. stuff is suspended */
  697. BUSY_CPU /* Locally busy (e.g. crypto); user interaction suspended */
  698. };
  699. void set_busy_status(Frontend *frontend, int status);
  700. int frontend_is_utf8(Frontend *frontend);
  701. void cleanup_exit(int);
  702. /*
  703. * Exports from conf.c, and a big enum (via parametric macro) of
  704. * configuration option keys.
  705. */
  706. #define CONFIG_OPTIONS(X) \
  707. /* X(value-type, subkey-type, keyword) */ \
  708. X(STR, NONE, host) \
  709. X(INT, NONE, port) \
  710. X(INT, NONE, protocol) \
  711. X(INT, NONE, addressfamily) \
  712. X(INT, NONE, close_on_exit) \
  713. X(INT, NONE, warn_on_close) \
  714. X(INT, NONE, ping_interval) /* in seconds */ \
  715. X(INT, NONE, tcp_nodelay) \
  716. X(INT, NONE, tcp_keepalives) \
  717. X(STR, NONE, loghost) /* logical host being contacted, for host key check */ \
  718. /* Proxy options */ \
  719. X(STR, NONE, proxy_exclude_list) \
  720. X(INT, NONE, proxy_dns) \
  721. X(INT, NONE, even_proxy_localhost) \
  722. X(INT, NONE, proxy_type) \
  723. X(STR, NONE, proxy_host) \
  724. X(INT, NONE, proxy_port) \
  725. X(STR, NONE, proxy_username) \
  726. X(STR, NONE, proxy_password) \
  727. X(STR, NONE, proxy_telnet_command) \
  728. X(INT, NONE, proxy_log_to_term) \
  729. /* SSH options */ \
  730. X(STR, NONE, remote_cmd) \
  731. X(STR, NONE, remote_cmd2) /* fallback if remote_cmd fails; never loaded or saved */ \
  732. X(INT, NONE, nopty) \
  733. X(INT, NONE, compression) \
  734. X(INT, INT, ssh_kexlist) \
  735. X(INT, INT, ssh_hklist) \
  736. X(INT, NONE, ssh_rekey_time) /* in minutes */ \
  737. X(STR, NONE, ssh_rekey_data) /* string encoding e.g. "100K", "2M", "1G" */ \
  738. X(INT, NONE, tryagent) \
  739. X(INT, NONE, agentfwd) \
  740. X(INT, NONE, change_username) /* allow username switching in SSH-2 */ \
  741. X(INT, INT, ssh_cipherlist) \
  742. X(FILENAME, NONE, keyfile) \
  743. /* \
  744. * Which SSH protocol to use. \
  745. * For historical reasons, the current legal values for CONF_sshprot \
  746. * are: \
  747. * 0 = SSH-1 only \
  748. * 3 = SSH-2 only \
  749. * We used to also support \
  750. * 1 = SSH-1 with fallback to SSH-2 \
  751. * 2 = SSH-2 with fallback to SSH-1 \
  752. * and we continue to use 0/3 in storage formats rather than the more \
  753. * obvious 1/2 to avoid surprises if someone saves a session and later \
  754. * downgrades PuTTY. So it's easier to use these numbers internally too. \
  755. */ \
  756. X(INT, NONE, sshprot) \
  757. X(INT, NONE, ssh2_des_cbc) /* "des-cbc" unrecommended SSH-2 cipher */ \
  758. X(INT, NONE, ssh_no_userauth) /* bypass "ssh-userauth" (SSH-2 only) */ \
  759. X(INT, NONE, ssh_show_banner) /* show USERAUTH_BANNERs (SSH-2 only) */ \
  760. X(INT, NONE, try_tis_auth) \
  761. X(INT, NONE, try_ki_auth) \
  762. X(INT, NONE, try_gssapi_auth) /* attempt gssapi auth via ssh userauth */ \
  763. X(INT, NONE, try_gssapi_kex) /* attempt gssapi auth via ssh kex */ \
  764. X(INT, NONE, gssapifwd) /* forward tgt via gss */ \
  765. X(INT, NONE, gssapirekey) /* KEXGSS refresh interval (mins) */ \
  766. X(INT, INT, ssh_gsslist) /* preference order for local GSS libs */ \
  767. X(FILENAME, NONE, ssh_gss_custom) \
  768. X(INT, NONE, ssh_subsys) /* run a subsystem rather than a command */ \
  769. X(INT, NONE, ssh_subsys2) /* fallback to go with remote_cmd_ptr2 */ \
  770. X(INT, NONE, ssh_no_shell) /* avoid running a shell */ \
  771. X(STR, NONE, ssh_nc_host) /* host to connect to in `nc' mode */ \
  772. X(INT, NONE, ssh_nc_port) /* port to connect to in `nc' mode */ \
  773. /* Telnet options */ \
  774. X(STR, NONE, termtype) \
  775. X(STR, NONE, termspeed) \
  776. X(STR, STR, ttymodes) /* values are "Vvalue" or "A" */ \
  777. X(STR, STR, environmt) \
  778. X(STR, NONE, username) \
  779. X(INT, NONE, username_from_env) \
  780. X(STR, NONE, localusername) \
  781. X(INT, NONE, rfc_environ) \
  782. X(INT, NONE, passive_telnet) \
  783. /* Serial port options */ \
  784. X(STR, NONE, serline) \
  785. X(INT, NONE, serspeed) \
  786. X(INT, NONE, serdatabits) \
  787. X(INT, NONE, serstopbits) \
  788. X(INT, NONE, serparity) \
  789. X(INT, NONE, serflow) \
  790. /* Keyboard options */ \
  791. X(INT, NONE, bksp_is_delete) \
  792. X(INT, NONE, rxvt_homeend) \
  793. X(INT, NONE, funky_type) \
  794. X(INT, NONE, no_applic_c) /* totally disable app cursor keys */ \
  795. X(INT, NONE, no_applic_k) /* totally disable app keypad */ \
  796. X(INT, NONE, no_mouse_rep) /* totally disable mouse reporting */ \
  797. X(INT, NONE, no_remote_resize) /* disable remote resizing */ \
  798. X(INT, NONE, no_alt_screen) /* disable alternate screen */ \
  799. X(INT, NONE, no_remote_wintitle) /* disable remote retitling */ \
  800. X(INT, NONE, no_remote_clearscroll) /* disable ESC[3J */ \
  801. X(INT, NONE, no_dbackspace) /* disable destructive backspace */ \
  802. X(INT, NONE, no_remote_charset) /* disable remote charset config */ \
  803. X(INT, NONE, remote_qtitle_action) /* remote win title query action */ \
  804. X(INT, NONE, app_cursor) \
  805. X(INT, NONE, app_keypad) \
  806. X(INT, NONE, nethack_keypad) \
  807. X(INT, NONE, telnet_keyboard) \
  808. X(INT, NONE, telnet_newline) \
  809. X(INT, NONE, alt_f4) /* is it special? */ \
  810. X(INT, NONE, alt_space) /* is it special? */ \
  811. X(INT, NONE, alt_only) /* is it special? */ \
  812. X(INT, NONE, localecho) \
  813. X(INT, NONE, localedit) \
  814. X(INT, NONE, alwaysontop) \
  815. X(INT, NONE, fullscreenonaltenter) \
  816. X(INT, NONE, scroll_on_key) \
  817. X(INT, NONE, scroll_on_disp) \
  818. X(INT, NONE, erase_to_scrollback) \
  819. X(INT, NONE, compose_key) \
  820. X(INT, NONE, ctrlaltkeys) \
  821. X(INT, NONE, osx_option_meta) \
  822. X(INT, NONE, osx_command_meta) \
  823. X(STR, NONE, wintitle) /* initial window title */ \
  824. /* Terminal options */ \
  825. X(INT, NONE, savelines) \
  826. X(INT, NONE, dec_om) \
  827. X(INT, NONE, wrap_mode) \
  828. X(INT, NONE, lfhascr) \
  829. X(INT, NONE, cursor_type) /* 0=block 1=underline 2=vertical */ \
  830. X(INT, NONE, blink_cur) \
  831. X(INT, NONE, beep) \
  832. X(INT, NONE, beep_ind) \
  833. X(INT, NONE, bellovl) /* bell overload protection active? */ \
  834. X(INT, NONE, bellovl_n) /* number of bells to cause overload */ \
  835. X(INT, NONE, bellovl_t) /* time interval for overload (seconds) */ \
  836. X(INT, NONE, bellovl_s) /* period of silence to re-enable bell (s) */ \
  837. X(FILENAME, NONE, bell_wavefile) \
  838. X(INT, NONE, scrollbar) \
  839. X(INT, NONE, scrollbar_in_fullscreen) \
  840. X(INT, NONE, resize_action) \
  841. X(INT, NONE, bce) \
  842. X(INT, NONE, blinktext) \
  843. X(INT, NONE, win_name_always) \
  844. X(INT, NONE, width) \
  845. X(INT, NONE, height) \
  846. X(FONT, NONE, font) \
  847. X(INT, NONE, font_quality) \
  848. X(FILENAME, NONE, logfilename) \
  849. X(INT, NONE, logtype) \
  850. X(INT, NONE, logxfovr) \
  851. X(INT, NONE, logflush) \
  852. X(INT, NONE, logheader) \
  853. X(INT, NONE, logomitpass) \
  854. X(INT, NONE, logomitdata) \
  855. X(INT, NONE, hide_mouseptr) \
  856. X(INT, NONE, sunken_edge) \
  857. X(INT, NONE, window_border) \
  858. X(STR, NONE, answerback) \
  859. X(STR, NONE, printer) \
  860. X(INT, NONE, arabicshaping) \
  861. X(INT, NONE, bidi) \
  862. /* Colour options */ \
  863. X(INT, NONE, ansi_colour) \
  864. X(INT, NONE, xterm_256_colour) \
  865. X(INT, NONE, true_colour) \
  866. X(INT, NONE, system_colour) \
  867. X(INT, NONE, try_palette) \
  868. X(INT, NONE, bold_style) \
  869. X(INT, INT, colours) \
  870. /* Selection options */ \
  871. X(INT, NONE, mouse_is_xterm) \
  872. X(INT, NONE, rect_select) \
  873. X(INT, NONE, paste_controls) \
  874. X(INT, NONE, rawcnp) \
  875. X(INT, NONE, utf8linedraw) \
  876. X(INT, NONE, rtf_paste) \
  877. X(INT, NONE, mouse_override) \
  878. X(INT, INT, wordness) \
  879. X(INT, NONE, mouseautocopy) \
  880. X(INT, NONE, mousepaste) \
  881. X(INT, NONE, ctrlshiftins) \
  882. X(INT, NONE, ctrlshiftcv) \
  883. X(STR, NONE, mousepaste_custom) \
  884. X(STR, NONE, ctrlshiftins_custom) \
  885. X(STR, NONE, ctrlshiftcv_custom) \
  886. /* translations */ \
  887. X(INT, NONE, vtmode) \
  888. X(STR, NONE, line_codepage) \
  889. X(INT, NONE, cjk_ambig_wide) \
  890. X(INT, NONE, utf8_override) \
  891. X(INT, NONE, xlat_capslockcyr) \
  892. /* X11 forwarding */ \
  893. X(INT, NONE, x11_forward) \
  894. X(STR, NONE, x11_display) \
  895. X(INT, NONE, x11_auth) \
  896. X(FILENAME, NONE, xauthfile) \
  897. /* port forwarding */ \
  898. X(INT, NONE, lport_acceptall) /* accept conns from hosts other than localhost */ \
  899. X(INT, NONE, rport_acceptall) /* same for remote forwarded ports (SSH-2 only) */ \
  900. /* \
  901. * Subkeys for 'portfwd' can have the following forms: \
  902. * \
  903. * [LR]localport \
  904. * [LR]localaddr:localport \
  905. * \
  906. * Dynamic forwardings are indicated by an 'L' key, and the \
  907. * special value "D". For all other forwardings, the value \
  908. * should be of the form 'host:port'. \
  909. */ \
  910. X(STR, STR, portfwd) \
  911. /* SSH bug compatibility modes */ \
  912. X(INT, NONE, sshbug_ignore1) \
  913. X(INT, NONE, sshbug_plainpw1) \
  914. X(INT, NONE, sshbug_rsa1) \
  915. X(INT, NONE, sshbug_hmac2) \
  916. X(INT, NONE, sshbug_derivekey2) \
  917. X(INT, NONE, sshbug_rsapad2) \
  918. X(INT, NONE, sshbug_pksessid2) \
  919. X(INT, NONE, sshbug_rekey2) \
  920. X(INT, NONE, sshbug_maxpkt2) \
  921. X(INT, NONE, sshbug_ignore2) \
  922. X(INT, NONE, sshbug_oldgex2) \
  923. X(INT, NONE, sshbug_winadj) \
  924. X(INT, NONE, sshbug_chanreq) \
  925. /* \
  926. * ssh_simple means that we promise never to open any channel \
  927. * other than the main one, which means it can safely use a very \
  928. * large window in SSH-2. \
  929. */ \
  930. X(INT, NONE, ssh_simple) \
  931. X(INT, NONE, ssh_connection_sharing) \
  932. X(INT, NONE, ssh_connection_sharing_upstream) \
  933. X(INT, NONE, ssh_connection_sharing_downstream) \
  934. /*
  935. * ssh_manual_hostkeys is conceptually a set rather than a
  936. * dictionary: the string subkeys are the important thing, and the
  937. * actual values to which those subkeys map are all "".
  938. */ \
  939. X(STR, STR, ssh_manual_hostkeys) \
  940. /* Options for pterm. Should split out into platform-dependent part. */ \
  941. X(INT, NONE, stamp_utmp) \
  942. X(INT, NONE, login_shell) \
  943. X(INT, NONE, scrollbar_on_left) \
  944. X(INT, NONE, shadowbold) \
  945. X(FONT, NONE, boldfont) \
  946. X(FONT, NONE, widefont) \
  947. X(FONT, NONE, wideboldfont) \
  948. X(INT, NONE, shadowboldoffset) \
  949. X(INT, NONE, crhaslf) \
  950. X(STR, NONE, winclass) \
  951. /* MPEXT BEGIN */ \
  952. X(INT, NONE, connect_timeout) \
  953. X(INT, NONE, sndbuf) \
  954. X(INT, NONE, force_remote_cmd2) \
  955. X(INT, NONE, change_password) \
  956. /* MPEXT END */ \
  957. /* Now define the actual enum of option keywords using that macro. */
  958. #define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
  959. enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
  960. #undef CONF_ENUM_DEF
  961. #define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
  962. /* Functions handling configuration structures. */
  963. Conf *conf_new(void); /* create an empty configuration */
  964. void conf_free(Conf *conf);
  965. Conf *conf_copy(Conf *oldconf);
  966. void conf_copy_into(Conf *dest, Conf *src);
  967. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  968. int conf_get_int(Conf *conf, int key);
  969. int conf_get_int_int(Conf *conf, int key, int subkey);
  970. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  971. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  972. Filename *conf_get_filename(Conf *conf, int key);
  973. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  974. /* Optional accessor function: return NULL if key does not exist. */
  975. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  976. /* Accessor function to step through a string-subkeyed list.
  977. * Returns the next subkey after the provided one, or the first if NULL.
  978. * Returns NULL if there are none left.
  979. * Both the return value and *subkeyout are still owned by conf. */
  980. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  981. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  982. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  983. /* Functions to set entries in configuration. Always copy their inputs. */
  984. void conf_set_int(Conf *conf, int key, int value);
  985. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  986. void conf_set_str(Conf *conf, int key, const char *value);
  987. void conf_set_str_str(Conf *conf, int key,
  988. const char *subkey, const char *val);
  989. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  990. void conf_set_filename(Conf *conf, int key, const Filename *val);
  991. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  992. /* Serialisation functions for Duplicate Session */
  993. void conf_serialise(BinarySink *bs, Conf *conf);
  994. int conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  995. /*
  996. * Functions to copy, free, serialise and deserialise FontSpecs.
  997. * Provided per-platform, to go with the platform's idea of a
  998. * FontSpec's contents.
  999. *
  1000. * fontspec_serialise returns the number of bytes written, and can
  1001. * handle data==NULL without crashing. So you can call it once to find
  1002. * out a size, then again once you've allocated a buffer.
  1003. */
  1004. FontSpec *fontspec_copy(const FontSpec *f);
  1005. void fontspec_free(FontSpec *f);
  1006. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1007. FontSpec *fontspec_deserialise(BinarySource *src);
  1008. /*
  1009. * Exports from noise.c.
  1010. */
  1011. void noise_get_heavy(void (*func) (void *, int));
  1012. void noise_get_light(void (*func) (void *, int));
  1013. void noise_regular(void);
  1014. void noise_ultralight(unsigned long data);
  1015. void random_save_seed(void);
  1016. void random_destroy_seed(void);
  1017. /*
  1018. * Exports from settings.c.
  1019. */
  1020. const struct BackendVtable *backend_vt_from_name(const char *name);
  1021. const struct BackendVtable *backend_vt_from_proto(int proto);
  1022. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1023. char *save_settings(const char *section, Conf *conf);
  1024. void save_open_settings(settings_w *sesskey, Conf *conf);
  1025. void load_settings(const char *section, Conf *conf);
  1026. void load_open_settings(settings_r *sesskey, Conf *conf);
  1027. void get_sesslist(struct sesslist *, int allocate);
  1028. void do_defaults(const char *, Conf *);
  1029. void registry_cleanup(void);
  1030. /*
  1031. * Functions used by settings.c to provide platform-specific
  1032. * default settings.
  1033. *
  1034. * (The integer one is expected to return `def' if it has no clear
  1035. * opinion of its own. This is because there's no integer value
  1036. * which I can reliably set aside to indicate `nil'. The string
  1037. * function is perfectly all right returning NULL, of course. The
  1038. * Filename and FontSpec functions are _not allowed_ to fail to
  1039. * return, since these defaults _must_ be per-platform.)
  1040. *
  1041. * The 'Filename *' returned by platform_default_filename, and the
  1042. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1043. * transferred to the caller, and must be freed.
  1044. */
  1045. char *platform_default_s(const char *name);
  1046. int platform_default_i(const char *name, int def);
  1047. Filename *platform_default_filename(const char *name);
  1048. FontSpec *platform_default_fontspec(const char *name);
  1049. /*
  1050. * Exports from terminal.c.
  1051. */
  1052. Terminal *term_init(Conf *, struct unicode_data *, Frontend *);
  1053. void term_free(Terminal *);
  1054. void term_size(Terminal *, int, int, int);
  1055. void term_paint(Terminal *, Context, int, int, int, int, int);
  1056. void term_scroll(Terminal *, int, int);
  1057. void term_scroll_to_selection(Terminal *, int);
  1058. void term_pwron(Terminal *, int);
  1059. void term_clrsb(Terminal *);
  1060. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  1061. int,int,int,int,int);
  1062. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  1063. unsigned int);
  1064. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  1065. void term_update(Terminal *);
  1066. void term_invalidate(Terminal *);
  1067. void term_blink(Terminal *, int set_cursor);
  1068. void term_do_paste(Terminal *, const wchar_t *, int);
  1069. void term_nopaste(Terminal *);
  1070. int term_ldisc(Terminal *, int option);
  1071. void term_copyall(Terminal *, const int *, int);
  1072. void term_reconfig(Terminal *, Conf *);
  1073. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  1074. void term_request_paste(Terminal *, int clipboard);
  1075. void term_seen_key_event(Terminal *);
  1076. int term_data(Terminal *, int is_stderr, const void *data, int len);
  1077. void term_provide_backend(Terminal *term, Backend *backend);
  1078. void term_provide_logctx(Terminal *term, LogContext *logctx);
  1079. void term_set_focus(Terminal *term, int has_focus);
  1080. char *term_get_ttymode(Terminal *term, const char *mode);
  1081. int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
  1082. int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);
  1083. /*
  1084. * Exports from logging.c.
  1085. */
  1086. struct LogPolicyVtable {
  1087. /*
  1088. * Pass Event Log entries on from LogContext to the front end,
  1089. * which might write them to standard error or save them for a GUI
  1090. * list box or other things.
  1091. */
  1092. void (*eventlog)(LogPolicy *lp, const char *event);
  1093. /*
  1094. * Ask what to do about the specified output log file already
  1095. * existing. Can return four values:
  1096. *
  1097. * - 2 means overwrite the log file
  1098. * - 1 means append to the log file
  1099. * - 0 means cancel logging for this session
  1100. * - -1 means please wait, and callback() will be called with one
  1101. * of those options.
  1102. */
  1103. int (*askappend)(LogPolicy *lp, Filename *filename,
  1104. void (*callback)(void *ctx, int result), void *ctx);
  1105. /*
  1106. * Emergency logging when the log file itself can't be opened,
  1107. * which typically means we want to shout about it more loudly
  1108. * than a mere Event Log entry.
  1109. *
  1110. * One reasonable option is to send it to the same place that
  1111. * stderr output from the main session goes (so, either a console
  1112. * tool's actual stderr, or a terminal window). In many cases this
  1113. * is unlikely to cause this error message to turn up
  1114. * embarrassingly in a log file of real server output, because the
  1115. * whole point is that we haven't managed to open any such log
  1116. * file :-)
  1117. */
  1118. void (*logging_error)(LogPolicy *lp, const char *event);
  1119. };
  1120. struct LogPolicy {
  1121. const LogPolicyVtable *vt;
  1122. };
  1123. #define lp_eventlog(lp, event) ((lp)->vt->eventlog(lp, event))
  1124. #define lp_askappend(lp, fn, cb, ctx) ((lp)->vt->askappend(lp, fn, cb, ctx))
  1125. #define lp_logging_error(lp, event) ((lp)->vt->logging_error(lp, event))
  1126. LogContext *log_init(LogPolicy *lp, Conf *conf, Frontend* frontend); // WINSCP
  1127. void log_free(LogContext *logctx);
  1128. void log_reconfig(LogContext *logctx, Conf *conf);
  1129. void logfopen(LogContext *logctx);
  1130. void logfclose(LogContext *logctx);
  1131. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  1132. void logflush(LogContext *logctx);
  1133. void logevent(LogContext *logctx, const char *event);
  1134. void logeventf(LogContext *logctx, const char *fmt, ...);
  1135. /*
  1136. * Pass a dynamically allocated string to logevent and immediately
  1137. * free it. Intended for use by wrapper macros which pass the return
  1138. * value of dupprintf straight to this.
  1139. */
  1140. void logevent_and_free(LogContext *logctx, char *event);
  1141. enum { PKT_INCOMING, PKT_OUTGOING };
  1142. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  1143. struct logblank_t {
  1144. int offset;
  1145. int len;
  1146. int type;
  1147. };
  1148. void log_packet(LogContext *logctx, int direction, int type,
  1149. const char *texttype, const void *data, int len,
  1150. int n_blanks, const struct logblank_t *blanks,
  1151. const unsigned long *sequence,
  1152. unsigned downstream_id, const char *additional_log_text);
  1153. /* This is defined by applications that have an obvious logging
  1154. * destination like standard error or the GUI. */
  1155. extern LogPolicy default_logpolicy[1];
  1156. /*
  1157. * Exports from testback.c
  1158. */
  1159. extern const struct BackendVtable null_backend;
  1160. extern const struct BackendVtable loop_backend;
  1161. /*
  1162. * Exports from raw.c.
  1163. */
  1164. extern const struct BackendVtable raw_backend;
  1165. /*
  1166. * Exports from rlogin.c.
  1167. */
  1168. extern const struct BackendVtable rlogin_backend;
  1169. /*
  1170. * Exports from telnet.c.
  1171. */
  1172. extern const struct BackendVtable telnet_backend;
  1173. /*
  1174. * Exports from ssh.c.
  1175. */
  1176. extern const struct BackendVtable ssh_backend;
  1177. /*
  1178. * Exports from ldisc.c.
  1179. */
  1180. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Frontend *);
  1181. void ldisc_configure(Ldisc *, Conf *);
  1182. void ldisc_free(Ldisc *);
  1183. void ldisc_send(Ldisc *, const void *buf, int len, int interactive);
  1184. void ldisc_echoedit_update(Ldisc *);
  1185. /*
  1186. * Exports from ldiscucs.c.
  1187. */
  1188. void lpage_send(Ldisc *, int codepage, const char *buf, int len,
  1189. int interactive);
  1190. void luni_send(Ldisc *, const wchar_t * widebuf, int len, int interactive);
  1191. /*
  1192. * Exports from sshrand.c.
  1193. */
  1194. void random_add_noise(void *noise, int length);
  1195. int random_byte(void);
  1196. void random_get_savedata(void **data, int *len);
  1197. extern int random_active;
  1198. /* The random number subsystem is activated if at least one other entity
  1199. * within the program expresses an interest in it. So each SSH session
  1200. * calls random_ref on startup and random_unref on shutdown. */
  1201. void random_ref(void);
  1202. void random_unref(void);
  1203. /*
  1204. * Exports from pinger.c.
  1205. */
  1206. typedef struct Pinger Pinger;
  1207. Pinger *pinger_new(Conf *conf, Backend *backend);
  1208. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  1209. void pinger_free(Pinger *);
  1210. /*
  1211. * Exports from misc.c.
  1212. */
  1213. #include "misc.h"
  1214. int conf_launchable(Conf *conf);
  1215. char const *conf_dest(Conf *conf);
  1216. /*
  1217. * Exports from sessprep.c.
  1218. */
  1219. void prepare_session(Conf *conf);
  1220. /*
  1221. * Exports from sercfg.c.
  1222. */
  1223. void ser_setup_config_box(struct controlbox *b, int midsession,
  1224. int parity_mask, int flow_mask);
  1225. /*
  1226. * Exports from version.c.
  1227. */
  1228. extern const char ver[];
  1229. /*
  1230. * Exports from unicode.c.
  1231. */
  1232. #ifndef CP_UTF8
  1233. #define CP_UTF8 65001
  1234. #endif
  1235. /* void init_ucs(void); -- this is now in platform-specific headers */
  1236. int is_dbcs_leadbyte(int codepage, char byte);
  1237. int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
  1238. wchar_t *wcstr, int wclen);
  1239. int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
  1240. char *mbstr, int mblen, const char *defchr,
  1241. struct unicode_data *ucsdata);
  1242. wchar_t xlat_uskbd2cyrllic(int ch);
  1243. int check_compose(int first, int second);
  1244. int decode_codepage(char *cp_name);
  1245. const char *cp_enumerate (int index);
  1246. const char *cp_name(int codepage);
  1247. void get_unitab(int codepage, wchar_t * unitab, int ftype);
  1248. /*
  1249. * Exports from wcwidth.c
  1250. */
  1251. int mk_wcwidth(unsigned int ucs);
  1252. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  1253. int mk_wcwidth_cjk(unsigned int ucs);
  1254. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  1255. /*
  1256. * Exports from pageantc.c.
  1257. *
  1258. * agent_query returns NULL for here's-a-response, and non-NULL for
  1259. * query-in- progress. In the latter case there will be a call to
  1260. * `callback' at some future point, passing callback_ctx as the first
  1261. * parameter and the actual reply data as the second and third.
  1262. *
  1263. * The response may be a NULL pointer (in either of the synchronous
  1264. * or asynchronous cases), which indicates failure to receive a
  1265. * response.
  1266. *
  1267. * When the return from agent_query is not NULL, it identifies the
  1268. * in-progress query in case it needs to be cancelled. If
  1269. * agent_cancel_query is called, then the pending query is destroyed
  1270. * and the callback will not be called. (E.g. if you're going to throw
  1271. * away the thing you were using as callback_ctx.)
  1272. *
  1273. * Passing a null pointer as callback forces agent_query to behave
  1274. * synchronously, i.e. it will block if necessary, and guarantee to
  1275. * return NULL. The wrapper function agent_query_synchronous() makes
  1276. * this easier.
  1277. */
  1278. typedef struct agent_pending_query agent_pending_query;
  1279. agent_pending_query *agent_query(
  1280. strbuf *in, void **out, int *outlen,
  1281. void (*callback)(void *, void *, int), void *callback_ctx);
  1282. void agent_cancel_query(agent_pending_query *);
  1283. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  1284. int agent_exists(void);
  1285. /*
  1286. * Exports from wildcard.c
  1287. */
  1288. const char *wc_error(int value);
  1289. int wc_match(const char *wildcard, const char *target);
  1290. int wc_unescape(char *output, const char *wildcard);
  1291. /*
  1292. * Exports from frontend (windlg.c etc)
  1293. */
  1294. void pgp_fingerprints(void);
  1295. /*
  1296. * verify_ssh_host_key() can return one of three values:
  1297. *
  1298. * - +1 means `key was OK' (either already known or the user just
  1299. * approved it) `so continue with the connection'
  1300. *
  1301. * - 0 means `key was not OK, abandon the connection'
  1302. *
  1303. * - -1 means `I've initiated enquiries, please wait to be called
  1304. * back via the provided function with a result that's either 0
  1305. * or +1'.
  1306. */
  1307. int verify_ssh_host_key(Frontend *frontend, char *host, int port,
  1308. const char *keytype, char *keystr, char *fingerprint,
  1309. void (*callback)(void *ctx, int result), void *ctx);
  1310. /*
  1311. * have_ssh_host_key() just returns true if a key of that type is
  1312. * already cached and false otherwise.
  1313. */
  1314. #ifdef MPEXT
  1315. int have_ssh_host_key(void *frontend, const char *host, int port, const char *keytype);
  1316. #else
  1317. int have_ssh_host_key(const char *host, int port, const char *keytype);
  1318. #endif
  1319. /*
  1320. * askalg and askhk have the same set of return values as
  1321. * verify_ssh_host_key.
  1322. *
  1323. * (askhk is used in the case where we're using a host key below the
  1324. * warning threshold because that's all we have cached, but at least
  1325. * one acceptable algorithm is available that we don't have cached.)
  1326. */
  1327. int askalg(Frontend *frontend, const char *algtype, const char *algname,
  1328. void (*callback)(void *ctx, int result), void *ctx);
  1329. int askhk(Frontend *frontend, const char *algname, const char *betteralgs,
  1330. void (*callback)(void *ctx, int result), void *ctx);
  1331. #ifdef MPEXT
  1332. void display_banner(Frontend *frontend, const char* banner, int size);
  1333. #endif
  1334. /*
  1335. * Exports from console frontends (wincons.c, uxcons.c)
  1336. * that aren't equivalents to things in windlg.c et al.
  1337. */
  1338. extern int console_batch_mode;
  1339. int console_get_userpass_input(prompts_t *p);
  1340. int is_interactive(void);
  1341. /*
  1342. * Exports from printing.c.
  1343. */
  1344. typedef struct printer_enum_tag printer_enum;
  1345. typedef struct printer_job_tag printer_job;
  1346. printer_enum *printer_start_enum(int *nprinters);
  1347. char *printer_get_name(printer_enum *, int);
  1348. void printer_finish_enum(printer_enum *);
  1349. printer_job *printer_start_job(char *printer);
  1350. void printer_job_data(printer_job *, void *, int);
  1351. void printer_finish_job(printer_job *);
  1352. /*
  1353. * Exports from cmdline.c (and also cmdline_error(), which is
  1354. * defined differently in various places and required _by_
  1355. * cmdline.c).
  1356. *
  1357. * Note that cmdline_process_param takes a const option string, but a
  1358. * writable argument string. That's not a mistake - that's so it can
  1359. * zero out password arguments in the hope of not having them show up
  1360. * avoidably in Unix 'ps'.
  1361. */
  1362. int cmdline_process_param(const char *, char *, int, Conf *);
  1363. void cmdline_run_saved(Conf *);
  1364. void cmdline_cleanup(void);
  1365. int cmdline_get_passwd_input(prompts_t *p);
  1366. int cmdline_host_ok(Conf *);
  1367. #define TOOLTYPE_FILETRANSFER 1
  1368. #define TOOLTYPE_NONNETWORK 2
  1369. #define TOOLTYPE_HOST_ARG 4
  1370. #define TOOLTYPE_HOST_ARG_CAN_BE_SESSION 8
  1371. #define TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX 16
  1372. #define TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD 32
  1373. #define TOOLTYPE_PORT_ARG 64
  1374. extern int cmdline_tooltype;
  1375. void cmdline_error(const char *, ...);
  1376. /*
  1377. * Exports from config.c.
  1378. */
  1379. struct controlbox;
  1380. union control;
  1381. void conf_radiobutton_handler(union control *ctrl, dlgparam *dlg,
  1382. void *data, int event);
  1383. #define CHECKBOX_INVERT (1<<30)
  1384. void conf_checkbox_handler(union control *ctrl, dlgparam *dlg,
  1385. void *data, int event);
  1386. void conf_editbox_handler(union control *ctrl, dlgparam *dlg,
  1387. void *data, int event);
  1388. void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
  1389. void *data, int event);
  1390. void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
  1391. void *data, int event);
  1392. void setup_config_box(struct controlbox *b, int midsession,
  1393. int protocol, int protcfginfo);
  1394. /*
  1395. * Exports from minibidi.c.
  1396. */
  1397. typedef struct bidi_char {
  1398. unsigned int origwc, wc;
  1399. unsigned short index;
  1400. } bidi_char;
  1401. int do_bidi(bidi_char *line, int count);
  1402. int do_shape(bidi_char *line, bidi_char *to, int count);
  1403. int is_rtl(int c);
  1404. /*
  1405. * X11 auth mechanisms we know about.
  1406. */
  1407. enum {
  1408. X11_NO_AUTH,
  1409. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  1410. X11_XDM, /* XDM-AUTHORIZATION-1 */
  1411. X11_NAUTHS
  1412. };
  1413. extern const char *const x11_authnames[]; /* declared in x11fwd.c */
  1414. /*
  1415. * An enum for the copy-paste UI action configuration.
  1416. */
  1417. enum {
  1418. CLIPUI_NONE, /* UI action has no copy/paste effect */
  1419. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  1420. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  1421. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  1422. };
  1423. /*
  1424. * Miscellaneous exports from the platform-specific code.
  1425. *
  1426. * filename_serialise and filename_deserialise have the same semantics
  1427. * as fontspec_serialise and fontspec_deserialise above.
  1428. */
  1429. Filename *filename_from_str(const char *string);
  1430. const char *filename_to_str(const Filename *fn);
  1431. int filename_equal(const Filename *f1, const Filename *f2);
  1432. int filename_is_null(const Filename *fn);
  1433. Filename *filename_copy(const Filename *fn);
  1434. void filename_free(Filename *fn);
  1435. void filename_serialise(BinarySink *bs, const Filename *f);
  1436. Filename *filename_deserialise(BinarySource *src);
  1437. char *get_username(void); /* return value needs freeing */
  1438. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  1439. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  1440. int open_for_write_would_lose_data(const Filename *fn);
  1441. /*
  1442. * Exports and imports from timing.c.
  1443. *
  1444. * schedule_timer() asks the front end to schedule a callback to a
  1445. * timer function in a given number of ticks. The returned value is
  1446. * the time (in ticks since an arbitrary offset) at which the
  1447. * callback can be expected. This value will also be passed as the
  1448. * `now' parameter to the callback function. Hence, you can (for
  1449. * example) schedule an event at a particular time by calling
  1450. * schedule_timer() and storing the return value in your context
  1451. * structure as the time when that event is due. The first time a
  1452. * callback function gives you that value or more as `now', you do
  1453. * the thing.
  1454. *
  1455. * expire_timer_context() drops all current timers associated with
  1456. * a given value of ctx (for when you're about to free ctx).
  1457. *
  1458. * run_timers() is called from the front end when it has reason to
  1459. * think some timers have reached their moment, or when it simply
  1460. * needs to know how long to wait next. We pass it the time we
  1461. * think it is. It returns TRUE and places the time when the next
  1462. * timer needs to go off in `next', or alternatively it returns
  1463. * FALSE if there are no timers at all pending.
  1464. *
  1465. * timer_change_notify() must be supplied by the front end; it
  1466. * notifies the front end that a new timer has been added to the
  1467. * list which is sooner than any existing ones. It provides the
  1468. * time when that timer needs to go off.
  1469. *
  1470. * *** FRONT END IMPLEMENTORS NOTE:
  1471. *
  1472. * There's an important subtlety in the front-end implementation of
  1473. * the timer interface. When a front end is given a `next' value,
  1474. * either returned from run_timers() or via timer_change_notify(),
  1475. * it should ensure that it really passes _that value_ as the `now'
  1476. * parameter to its next run_timers call. It should _not_ simply
  1477. * call GETTICKCOUNT() to get the `now' parameter when invoking
  1478. * run_timers().
  1479. *
  1480. * The reason for this is that an OS's system clock might not agree
  1481. * exactly with the timing mechanisms it supplies to wait for a
  1482. * given interval. I'll illustrate this by the simple example of
  1483. * Unix Plink, which uses timeouts to select() in a way which for
  1484. * these purposes can simply be considered to be a wait() function.
  1485. * Suppose, for the sake of argument, that this wait() function
  1486. * tends to return early by 1%. Then a possible sequence of actions
  1487. * is:
  1488. *
  1489. * - run_timers() tells the front end that the next timer firing
  1490. * is 10000ms from now.
  1491. * - Front end calls wait(10000ms), but according to
  1492. * GETTICKCOUNT() it has only waited for 9900ms.
  1493. * - Front end calls run_timers() again, passing time T-100ms as
  1494. * `now'.
  1495. * - run_timers() does nothing, and says the next timer firing is
  1496. * still 100ms from now.
  1497. * - Front end calls wait(100ms), which only waits for 99ms.
  1498. * - Front end calls run_timers() yet again, passing time T-1ms.
  1499. * - run_timers() says there's still 1ms to wait.
  1500. * - Front end calls wait(1ms).
  1501. *
  1502. * If you're _lucky_ at this point, wait(1ms) will actually wait
  1503. * for 1ms and you'll only have woken the program up three times.
  1504. * If you're unlucky, wait(1ms) might do nothing at all due to
  1505. * being below some minimum threshold, and you might find your
  1506. * program spends the whole of the last millisecond tight-looping
  1507. * between wait() and run_timers().
  1508. *
  1509. * Instead, what you should do is to _save_ the precise `next'
  1510. * value provided by run_timers() or via timer_change_notify(), and
  1511. * use that precise value as the input to the next run_timers()
  1512. * call. So:
  1513. *
  1514. * - run_timers() tells the front end that the next timer firing
  1515. * is at time T, 10000ms from now.
  1516. * - Front end calls wait(10000ms).
  1517. * - Front end then immediately calls run_timers() and passes it
  1518. * time T, without stopping to check GETTICKCOUNT() at all.
  1519. *
  1520. * This guarantees that the program wakes up only as many times as
  1521. * there are actual timer actions to be taken, and that the timing
  1522. * mechanism will never send it into a tight loop.
  1523. *
  1524. * (It does also mean that the timer action in the above example
  1525. * will occur 100ms early, but this is not generally critical. And
  1526. * the hypothetical 1% error in wait() will be partially corrected
  1527. * for anyway when, _after_ run_timers() returns, you call
  1528. * GETTICKCOUNT() and compare the result with the returned `next'
  1529. * value to find out how long you have to make your next wait().)
  1530. */
  1531. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  1532. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  1533. void expire_timer_context(void *ctx);
  1534. int run_timers(unsigned long now, unsigned long *next);
  1535. void timer_change_notify(unsigned long next);
  1536. unsigned long timing_last_clock(void);
  1537. /*
  1538. * Exports from callback.c.
  1539. *
  1540. * This provides a method of queuing function calls to be run at the
  1541. * earliest convenience from the top-level event loop. Use it if
  1542. * you're deep in a nested chain of calls and want to trigger an
  1543. * action which will probably lead to your function being re-entered
  1544. * recursively if you just call the initiating function the normal
  1545. * way.
  1546. *
  1547. * Most front ends run the queued callbacks by simply calling
  1548. * run_toplevel_callbacks() after handling each event in their
  1549. * top-level event loop. However, if a front end doesn't have control
  1550. * over its own event loop (e.g. because it's using GTK) then it can
  1551. * instead request notifications when a callback is available, so that
  1552. * it knows to ask its delegate event loop to do the same thing. Also,
  1553. * if a front end needs to know whether a callback is pending without
  1554. * actually running it (e.g. so as to put a zero timeout on a select()
  1555. * call) then it can call toplevel_callback_pending(), which will
  1556. * return true if at least one callback is in the queue.
  1557. *
  1558. * run_toplevel_callbacks() returns TRUE if it ran any actual code.
  1559. * This can be used as a means of speculatively terminating a select
  1560. * loop, as in PSFTP, for example - if a callback has run then perhaps
  1561. * it might have done whatever the loop's caller was waiting for.
  1562. */
  1563. typedef void (*toplevel_callback_fn_t)(void *ctx);
  1564. #ifdef MPEXT
  1565. typedef struct callback callback;
  1566. struct IdempotentCallback;
  1567. typedef struct PacketQueueNode PacketQueueNode;
  1568. struct callback_set {
  1569. struct callback *cbcurr, *cbhead, *cbtail;
  1570. IdempotentCallback * ic_pktin_free;
  1571. PacketQueueNode * pktin_freeq_head;
  1572. };
  1573. #define CALLBACK_SET_ONLY struct callback_set * callback_set_v
  1574. #define CALLBACK_SET CALLBACK_SET_ONLY,
  1575. #else
  1576. #define CALLBACK_SET_ONLY void
  1577. #define CALLBACK_SET
  1578. #endif
  1579. void queue_toplevel_callback(CALLBACK_SET toplevel_callback_fn_t fn, void *ctx);
  1580. int run_toplevel_callbacks(CALLBACK_SET_ONLY);
  1581. int toplevel_callback_pending(CALLBACK_SET_ONLY);
  1582. struct callback_set * get_callback_set(Plug * plug);
  1583. struct callback_set * get_frontend_callback_set(Frontend * frontend);
  1584. void delete_callbacks_for_context(CALLBACK_SET void *ctx);
  1585. Frontend *log_get_frontend(LogContext *ctx); // WINSCP
  1586. /*
  1587. * Another facility in callback.c deals with 'idempotent' callbacks,
  1588. * defined as those which never need to be scheduled again if they are
  1589. * already scheduled and have not yet run. (An example would be one
  1590. * which, when called, empties a queue of data completely: when data
  1591. * is added to the queue, you must ensure a run of the queue-consuming
  1592. * function has been scheduled, but if one is already pending, you
  1593. * don't need to schedule a second one.)
  1594. */
  1595. struct IdempotentCallback {
  1596. toplevel_callback_fn_t fn;
  1597. void *ctx;
  1598. int queued;
  1599. struct callback_set * set;
  1600. };
  1601. void queue_idempotent_callback(struct IdempotentCallback *ic);
  1602. #ifndef MPEXT
  1603. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  1604. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  1605. void *ctx);
  1606. #endif
  1607. /*
  1608. * Define no-op macros for the jump list functions, on platforms that
  1609. * don't support them. (This is a bit of a hack, and it'd be nicer to
  1610. * localise even the calls to those functions into the Windows front
  1611. * end, but it'll do for the moment.)
  1612. */
  1613. #ifndef JUMPLIST_SUPPORTED
  1614. #define add_session_to_jumplist(x) ((void)0)
  1615. #define remove_session_from_jumplist(x) ((void)0)
  1616. #endif
  1617. /* SURROGATE PAIR */
  1618. #define HIGH_SURROGATE_START 0xd800
  1619. #define HIGH_SURROGATE_END 0xdbff
  1620. #define LOW_SURROGATE_START 0xdc00
  1621. #define LOW_SURROGATE_END 0xdfff
  1622. /* These macros exist in the Windows API, so the environment may
  1623. * provide them. If not, define them in terms of the above. */
  1624. #ifndef IS_HIGH_SURROGATE
  1625. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1626. ((wch) <= HIGH_SURROGATE_END))
  1627. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  1628. ((wch) <= LOW_SURROGATE_END))
  1629. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  1630. IS_LOW_SURROGATE(ls))
  1631. #endif
  1632. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  1633. ((wch) <= LOW_SURROGATE_END))
  1634. #define HIGH_SURROGATE_OF(codept) \
  1635. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  1636. #define LOW_SURROGATE_OF(codept) \
  1637. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  1638. #define FROM_SURROGATES(wch1, wch2) \
  1639. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  1640. #ifdef MPEXT
  1641. extern CRITICAL_SECTION putty_section;
  1642. void putty_initialize();
  1643. void putty_finalize();
  1644. void pktin_free_queue_callback(void *vctx);
  1645. #define MPEXT_PUTTY_SECTION_ENTER EnterCriticalSection(&putty_section);
  1646. #define MPEXT_PUTTY_SECTION_LEAVE LeaveCriticalSection(&putty_section);
  1647. #else
  1648. #define MPEXT_PUTTY_SECTION_ENTER
  1649. #define MPEXT_PUTTY_SECTION_LEAVE
  1650. #endif
  1651. #ifdef MPEXT
  1652. // To mark carefully selected messages from PuTTY code as UTF-8.
  1653. // Only for messages that are certain not to ever get ansi-encoded component,
  1654. // but known to get UTF-8 encoded component (currently private key path only)
  1655. #define WINSCP_BOM "\xEF\xBB\xBF"
  1656. #endif
  1657. #ifdef MPEXT
  1658. // Recent PuTTY code uses C99 standard that allows code before initialization.
  1659. // Mostly that code are assertions. This assert implementation allows being used before code.
  1660. #define pinitassert(P) const int __assert_dummy = 1/(P)
  1661. #endif
  1662. #endif