putty.h 58 KB

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