putty.h 56 KB

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