putty.h 54 KB

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