putty.h 54 KB

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