putty.h 63 KB

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