putty.h 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799
  1. #ifndef PUTTY_PUTTY_H
  2. #define PUTTY_PUTTY_H
  3. #include <stddef.h> /* for wchar_t */
  4. #include <limits.h> /* for INT_MAX */
  5. #include "defs.h"
  6. #include "platform.h"
  7. #include "network.h"
  8. #include "misc.h"
  9. #include "marshal.h"
  10. /*
  11. * We express various time intervals in unsigned long minutes, but may need to
  12. * clip some values so that the resulting number of ticks does not overflow an
  13. * integer value.
  14. */
  15. #define MAX_TICK_MINS (INT_MAX / (60 * TICKSPERSEC))
  16. /*
  17. * Fingerprints of the current and previous PGP master keys, to
  18. * establish a trust path between an executable and other files.
  19. */
  20. #define PGP_MASTER_KEY_YEAR "2023"
  21. #define PGP_MASTER_KEY_DETAILS "RSA, 4096-bit"
  22. #define PGP_MASTER_KEY_FP \
  23. "28D4 7C46 55E7 65A6 D827 AC66 B15D 9EFC 216B 06A1"
  24. #define PGP_PREV_MASTER_KEY_YEAR "2021"
  25. #define PGP_PREV_MASTER_KEY_DETAILS "RSA, 3072-bit"
  26. #define PGP_PREV_MASTER_KEY_FP \
  27. "A872 D42F 1660 890F 0E05 223E DD43 55EA AC11 19DE"
  28. /*
  29. * Definitions of three separate indexing schemes for colour palette
  30. * entries.
  31. *
  32. * Why three? Because history, sorry.
  33. *
  34. * Two of the colour indexings are used in escape sequences. The
  35. * Linux-console style OSC P sequences for setting the palette use an
  36. * indexing in which the eight standard ANSI SGR colours come first,
  37. * then their bold versions, and then six extra colours for default
  38. * fg/bg and the terminal cursor. And the xterm OSC 4 sequences for
  39. * querying the palette use a related indexing in which the six extra
  40. * colours are pushed up to indices 256 and onwards, with the previous
  41. * 16 being the first part of the xterm 256-colour space, and 240
  42. * additional terminal-accessible colours inserted in the middle.
  43. *
  44. * The third indexing is the order that the colours appear in the
  45. * PuTTY configuration panel, and also the order in which they're
  46. * described in the saved session files. This order specifies the same
  47. * set of colours as the OSC P encoding, but in a different order,
  48. * with the default fg/bg colours (which users are most likely to want
  49. * to reconfigure) at the start, and the ANSI SGR colours coming
  50. * later.
  51. *
  52. * So all three indices really are needed, because all three appear in
  53. * protocols or file formats outside the PuTTY binary. (Changing the
  54. * saved-session encoding would have a backwards-compatibility impact;
  55. * also, if we ever do, it would be better to replace the numeric
  56. * indices with descriptive keywords.)
  57. *
  58. * Since the OSC 4 encoding contains the full set of colours used in
  59. * the terminal display, that's the encoding used by front ends to
  60. * store any actual data associated with their palette entries. So the
  61. * TermWin palette_set and palette_get_overrides methods use that
  62. * encoding, and so does the bitwise encoding of attribute words used
  63. * in terminal redraw operations.
  64. *
  65. * The Conf encoding, of course, is used by config.c and settings.c.
  66. *
  67. * The aim is that those two sections of the code should never need to
  68. * come directly into contact, and the only module that should have to
  69. * deal directly with the mapping between these colour encodings - or
  70. * to deal _at all_ with the intermediate OSC P encoding - is
  71. * terminal.c itself.
  72. */
  73. #define CONF_NCOLOURS 22 /* 16 + 6 special ones */
  74. #define OSCP_NCOLOURS 22 /* same as CONF, but different order */
  75. #define OSC4_NCOLOURS 262 /* 256 + the same 6 special ones */
  76. /* The list macro for the conf colours also gives the textual names
  77. * used in the GUI configurer */
  78. #define CONF_COLOUR_LIST(X) \
  79. X(fg, "Default Foreground") \
  80. X(fg_bold, "Default Bold Foreground") \
  81. X(bg, "Default Background") \
  82. X(bg_bold, "Default Bold Background") \
  83. X(cursor_fg, "Cursor Text") \
  84. X(cursor_bg, "Cursor Colour") \
  85. X(black, "ANSI Black") \
  86. X(black_bold, "ANSI Black Bold") \
  87. X(red, "ANSI Red") \
  88. X(red_bold, "ANSI Red Bold") \
  89. X(green, "ANSI Green") \
  90. X(green_bold, "ANSI Green Bold") \
  91. X(yellow, "ANSI Yellow") \
  92. X(yellow_bold, "ANSI Yellow Bold") \
  93. X(blue, "ANSI Blue") \
  94. X(blue_bold, "ANSI Blue Bold") \
  95. X(magenta, "ANSI Magenta") \
  96. X(magenta_bold, "ANSI Magenta Bold") \
  97. X(cyan, "ANSI Cyan") \
  98. X(cyan_bold, "ANSI Cyan Bold") \
  99. X(white, "ANSI White") \
  100. X(white_bold, "ANSI White Bold") \
  101. /* end of list */
  102. #define OSCP_COLOUR_LIST(X) \
  103. X(black) \
  104. X(red) \
  105. X(green) \
  106. X(yellow) \
  107. X(blue) \
  108. X(magenta) \
  109. X(cyan) \
  110. X(white) \
  111. X(black_bold) \
  112. X(red_bold) \
  113. X(green_bold) \
  114. X(yellow_bold) \
  115. X(blue_bold) \
  116. X(magenta_bold) \
  117. X(cyan_bold) \
  118. X(white_bold) \
  119. /*
  120. * In the OSC 4 indexing, this is where the extra 240 colours go.
  121. * They consist of:
  122. *
  123. * - 216 colours forming a 6x6x6 cube, with R the most
  124. * significant colour and G the least. In other words, these
  125. * occupy the space of indices 16 <= i < 232, with each
  126. * individual colour found as i = 16 + 36*r + 6*g + b, for all
  127. * 0 <= r,g,b <= 5.
  128. *
  129. * - The remaining indices, 232 <= i < 256, consist of a uniform
  130. * series of grey shades running between black and white (but
  131. * not including either, since actual black and white are
  132. * already provided in the previous colour cube).
  133. *
  134. * After that, we have the remaining 6 special colours:
  135. */ \
  136. X(fg) \
  137. X(fg_bold) \
  138. X(bg) \
  139. X(bg_bold) \
  140. X(cursor_fg) \
  141. X(cursor_bg) \
  142. /* end of list */
  143. /* Enumerations of the colour lists. These are available everywhere in
  144. * the code. The OSC P encoding shouldn't be used outside terminal.c,
  145. * but the easiest way to define the OSC 4 enum is to have the OSC P
  146. * one available to compute with. */
  147. enum {
  148. #define ENUM_DECL(id,name) CONF_COLOUR_##id,
  149. CONF_COLOUR_LIST(ENUM_DECL)
  150. #undef ENUM_DECL
  151. };
  152. enum {
  153. #define ENUM_DECL(id) OSCP_COLOUR_##id,
  154. OSCP_COLOUR_LIST(ENUM_DECL)
  155. #undef ENUM_DECL
  156. };
  157. enum {
  158. #define ENUM_DECL(id) OSC4_COLOUR_##id = \
  159. OSCP_COLOUR_##id + (OSCP_COLOUR_##id >= 16 ? 240 : 0),
  160. OSCP_COLOUR_LIST(ENUM_DECL)
  161. #undef ENUM_DECL
  162. };
  163. /* Mapping tables defined in terminal.c */
  164. extern const int colour_indices_conf_to_oscp[CONF_NCOLOURS];
  165. extern const int colour_indices_conf_to_osc4[CONF_NCOLOURS];
  166. extern const int colour_indices_oscp_to_osc4[OSCP_NCOLOURS];
  167. /* Three attribute types:
  168. * The ATTRs (normal attributes) are stored with the characters in
  169. * the main display arrays
  170. *
  171. * The TATTRs (temporary attributes) are generated on the fly, they
  172. * can overlap with characters but not with normal attributes.
  173. *
  174. * The LATTRs (line attributes) are an entirely disjoint space of
  175. * flags.
  176. *
  177. * The DATTRs (display attributes) are internal to terminal.c (but
  178. * defined here because their values have to match the others
  179. * here); they reuse the TATTR_* space but are always masked off
  180. * before sending to the front end.
  181. *
  182. * ATTR_INVALID is an illegal colour combination.
  183. */
  184. #define TATTR_ACTCURS 0x40000000UL /* active cursor (block) */
  185. #define TATTR_PASCURS 0x20000000UL /* passive cursor (box) */
  186. #define TATTR_RIGHTCURS 0x10000000UL /* cursor-on-RHS */
  187. #define TATTR_COMBINING 0x80000000UL /* combining characters */
  188. #define DATTR_STARTRUN 0x80000000UL /* start of redraw run */
  189. #define TDATTR_MASK 0xF0000000UL
  190. #define TATTR_MASK (TDATTR_MASK)
  191. #define DATTR_MASK (TDATTR_MASK)
  192. #define LATTR_NORM 0x00000000UL
  193. #define LATTR_WIDE 0x00000001UL
  194. #define LATTR_TOP 0x00000002UL
  195. #define LATTR_BOT 0x00000003UL
  196. #define LATTR_MODE 0x00000003UL
  197. #define LATTR_WRAPPED 0x00000010UL /* this line wraps to next */
  198. #define LATTR_WRAPPED2 0x00000020UL /* with WRAPPED: CJK wide character
  199. wrapped to next line, so last
  200. single-width cell is empty */
  201. #define ATTR_INVALID 0x03FFFFU
  202. /* Use the DC00 page for direct to font. */
  203. #define CSET_OEMCP 0x0000DC00UL /* OEM Codepage DTF */
  204. #define CSET_ACP 0x0000DD00UL /* Ansi Codepage DTF */
  205. /* These are internal use overlapping with the UTF-16 surrogates */
  206. #define CSET_ASCII 0x0000D800UL /* normal ASCII charset ESC ( B */
  207. #define CSET_LINEDRW 0x0000D900UL /* line drawing charset ESC ( 0 */
  208. #define CSET_SCOACS 0x0000DA00UL /* SCO Alternate charset */
  209. #define CSET_GBCHR 0x0000DB00UL /* UK variant charset ESC ( A */
  210. #define CSET_MASK 0xFFFFFF00UL /* Character set mask */
  211. #define DIRECT_CHAR(c) ((c&0xFFFFFC00)==0xD800)
  212. #define DIRECT_FONT(c) ((c&0xFFFFFE00)==0xDC00)
  213. #define UCSERR (CSET_LINEDRW|'a') /* UCS Format error character. */
  214. /*
  215. * UCSWIDE is a special value used in the terminal data to signify
  216. * the character cell containing the right-hand half of a CJK wide
  217. * character. We use 0xDFFF because it's part of the surrogate
  218. * range and hence won't be used for anything else (it's impossible
  219. * to input it via UTF-8 because our UTF-8 decoder correctly
  220. * rejects surrogates).
  221. */
  222. #define UCSWIDE 0xDFFF
  223. #define ATTR_NARROW 0x0800000U
  224. #define ATTR_WIDE 0x0400000U
  225. #define ATTR_BOLD 0x0040000U
  226. #define ATTR_UNDER 0x0080000U
  227. #define ATTR_REVERSE 0x0100000U
  228. #define ATTR_BLINK 0x0200000U
  229. #define ATTR_FGMASK 0x00001FFU /* stores a colour in OSC 4 indexing */
  230. #define ATTR_BGMASK 0x003FE00U /* stores a colour in OSC 4 indexing */
  231. #define ATTR_COLOURS 0x003FFFFU
  232. #define ATTR_DIM 0x1000000U
  233. #define ATTR_STRIKE 0x2000000U
  234. #define ATTR_FGSHIFT 0
  235. #define ATTR_BGSHIFT 9
  236. #define ATTR_DEFFG (OSC4_COLOUR_fg << ATTR_FGSHIFT)
  237. #define ATTR_DEFBG (OSC4_COLOUR_bg << ATTR_BGSHIFT)
  238. #define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
  239. struct sesslist {
  240. int nsessions;
  241. const char **sessions;
  242. char *buffer; /* so memory can be freed later */
  243. };
  244. struct unicode_data {
  245. bool dbcs_screenfont;
  246. int font_codepage;
  247. int line_codepage;
  248. wchar_t unitab_scoacs[256];
  249. wchar_t unitab_line[256];
  250. wchar_t unitab_font[256];
  251. wchar_t unitab_xterm[256];
  252. wchar_t unitab_oemcp[256];
  253. unsigned char unitab_ctrl[256];
  254. };
  255. #define LGXF_OVR 1 /* existing logfile overwrite */
  256. #define LGXF_APN 0 /* existing logfile append */
  257. #define LGXF_ASK -1 /* existing logfile ask */
  258. #define LGTYP_NONE 0 /* logmode: no logging */
  259. #define LGTYP_ASCII 1 /* logmode: pure ascii */
  260. #define LGTYP_DEBUG 2 /* logmode: all chars of traffic */
  261. #define LGTYP_PACKETS 3 /* logmode: SSH data packets */
  262. #define LGTYP_SSHRAW 4 /* logmode: SSH raw data */
  263. /* Platform-generic function to set up a struct unicode_data. This is
  264. * only likely to be useful to test programs; real clients will want
  265. * to use the more flexible per-platform setup functions. */
  266. void init_ucs_generic(Conf *conf, struct unicode_data *ucsdata);
  267. /*
  268. * Enumeration of 'special commands' that can be sent during a
  269. * session, separately from the byte stream of ordinary session data.
  270. */
  271. typedef enum {
  272. /* The list of enum constants is defined in a separate header so
  273. * they can be reused in other contexts */
  274. #define SPECIAL(x) SS_ ## x,
  275. #include "specials.h"
  276. #undef SPECIAL
  277. } SessionSpecialCode;
  278. /*
  279. * The structure type returned from backend_get_specials.
  280. */
  281. struct SessionSpecial {
  282. const char *name;
  283. SessionSpecialCode code;
  284. int arg;
  285. };
  286. /* Needed by both ssh/channel.h and ssh/ppl.h */
  287. typedef void (*add_special_fn_t)(
  288. void *ctx, const char *text, SessionSpecialCode code, int arg);
  289. typedef enum {
  290. MBT_NOTHING,
  291. MBT_LEFT, MBT_MIDDLE, MBT_RIGHT, /* `raw' button designations */
  292. MBT_SELECT, MBT_EXTEND, MBT_PASTE, /* `cooked' button designations */
  293. MBT_WHEEL_UP, MBT_WHEEL_DOWN, /* vertical mouse wheel */
  294. MBT_WHEEL_LEFT, MBT_WHEEL_RIGHT /* horizontal mouse wheel */
  295. } Mouse_Button;
  296. typedef enum {
  297. MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE, MA_MOVE
  298. } Mouse_Action;
  299. /* Keyboard modifiers -- keys the user is actually holding down */
  300. #define PKM_SHIFT 0x01
  301. #define PKM_CONTROL 0x02
  302. #define PKM_META 0x04
  303. #define PKM_ALT 0x08
  304. /* Keyboard flags that aren't really modifiers */
  305. #define PKF_CAPSLOCK 0x10
  306. #define PKF_NUMLOCK 0x20
  307. #define PKF_REPEAT 0x40
  308. /* Stand-alone keysyms for function keys */
  309. typedef enum {
  310. PK_NULL, /* No symbol for this key */
  311. /* Main keypad keys */
  312. PK_ESCAPE, PK_TAB, PK_BACKSPACE, PK_RETURN, PK_COMPOSE,
  313. /* Editing keys */
  314. PK_HOME, PK_INSERT, PK_DELETE, PK_END, PK_PAGEUP, PK_PAGEDOWN,
  315. /* Cursor keys */
  316. PK_UP, PK_DOWN, PK_RIGHT, PK_LEFT, PK_REST,
  317. /* Numeric keypad */ /* Real one looks like: */
  318. PK_PF1, PK_PF2, PK_PF3, PK_PF4, /* PF1 PF2 PF3 PF4 */
  319. PK_KPCOMMA, PK_KPMINUS, PK_KPDECIMAL, /* 7 8 9 - */
  320. PK_KP0, PK_KP1, PK_KP2, PK_KP3, PK_KP4, /* 4 5 6 , */
  321. PK_KP5, PK_KP6, PK_KP7, PK_KP8, PK_KP9, /* 1 2 3 en- */
  322. PK_KPBIGPLUS, PK_KPENTER, /* 0 . ter */
  323. /* Top row */
  324. PK_F1, PK_F2, PK_F3, PK_F4, PK_F5,
  325. PK_F6, PK_F7, PK_F8, PK_F9, PK_F10,
  326. PK_F11, PK_F12, PK_F13, PK_F14, PK_F15,
  327. PK_F16, PK_F17, PK_F18, PK_F19, PK_F20,
  328. PK_PAUSE
  329. } Key_Sym;
  330. #define PK_ISEDITING(k) ((k) >= PK_HOME && (k) <= PK_PAGEDOWN)
  331. #define PK_ISCURSOR(k) ((k) >= PK_UP && (k) <= PK_REST)
  332. #define PK_ISKEYPAD(k) ((k) >= PK_PF1 && (k) <= PK_KPENTER)
  333. #define PK_ISFKEY(k) ((k) >= PK_F1 && (k) <= PK_F20)
  334. enum {
  335. VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN, VT_UNICODE
  336. };
  337. enum {
  338. /*
  339. * SSH-2 key exchange algorithms
  340. */
  341. KEX_WARN,
  342. KEX_DHGROUP1,
  343. KEX_DHGROUP14,
  344. KEX_DHGROUP15,
  345. KEX_DHGROUP16,
  346. KEX_DHGROUP17,
  347. KEX_DHGROUP18,
  348. KEX_DHGEX,
  349. KEX_RSA,
  350. KEX_ECDH,
  351. KEX_NTRU_HYBRID,
  352. KEX_MAX
  353. };
  354. enum {
  355. /*
  356. * SSH-2 host key algorithms
  357. */
  358. HK_WARN,
  359. HK_RSA,
  360. HK_DSA,
  361. HK_ECDSA,
  362. HK_ED25519,
  363. HK_ED448,
  364. HK_MAX
  365. };
  366. enum {
  367. /*
  368. * SSH ciphers (both SSH-1 and SSH-2)
  369. */
  370. CIPHER_WARN, /* pseudo 'cipher' */
  371. CIPHER_3DES,
  372. CIPHER_BLOWFISH,
  373. CIPHER_AES, /* (SSH-2 only) */
  374. CIPHER_DES,
  375. CIPHER_ARCFOUR,
  376. CIPHER_CHACHA20,
  377. CIPHER_AESGCM,
  378. CIPHER_MAX /* no. ciphers (inc warn) */
  379. };
  380. enum TriState {
  381. /*
  382. * Several different bits of the PuTTY configuration seem to be
  383. * three-way settings whose values are `always yes', `always
  384. * no', and `decide by some more complex automated means'. This
  385. * is true of line discipline options (local echo and line
  386. * editing), proxy DNS, proxy terminal logging, Close On Exit, and
  387. * SSH server bug workarounds. Accordingly I supply a single enum
  388. * here to deal with them all.
  389. */
  390. FORCE_ON, FORCE_OFF, AUTO
  391. };
  392. enum {
  393. /*
  394. * Proxy types.
  395. */
  396. PROXY_NONE, PROXY_SOCKS4, PROXY_SOCKS5,
  397. PROXY_HTTP, PROXY_TELNET, PROXY_CMD, PROXY_SSH_TCPIP,
  398. PROXY_SSH_EXEC, PROXY_SSH_SUBSYSTEM,
  399. PROXY_FUZZ
  400. };
  401. enum {
  402. /*
  403. * Line discipline options which the backend might try to control.
  404. */
  405. LD_EDIT, /* local line editing */
  406. LD_ECHO, /* local echo */
  407. LD_N_OPTIONS
  408. };
  409. enum {
  410. /* Actions on remote window title query */
  411. TITLE_NONE, TITLE_EMPTY, TITLE_REAL
  412. };
  413. enum {
  414. /* SUPDUP character set options */
  415. SUPDUP_CHARSET_ASCII, SUPDUP_CHARSET_ITS, SUPDUP_CHARSET_WAITS
  416. };
  417. enum {
  418. /* Protocol back ends. (CONF_protocol) */
  419. PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, PROT_SSHCONN,
  420. /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
  421. * hurt to define it globally. */
  422. PROT_SERIAL,
  423. /* PROT_SUPDUP is the historical RFC 734 protocol. */
  424. PROT_SUPDUP,
  425. PROTOCOL_LIMIT, /* upper bound on number of protocols */
  426. };
  427. enum {
  428. /* Bell settings (CONF_beep) */
  429. BELL_DISABLED, BELL_DEFAULT, BELL_VISUAL, BELL_WAVEFILE, BELL_PCSPEAKER
  430. };
  431. enum {
  432. /* Taskbar flashing indication on bell (CONF_beep_ind) */
  433. B_IND_DISABLED, B_IND_FLASH, B_IND_STEADY
  434. };
  435. enum {
  436. /* Resize actions (CONF_resize_action) */
  437. RESIZE_TERM, RESIZE_DISABLED, RESIZE_FONT, RESIZE_EITHER
  438. };
  439. enum {
  440. /* Mouse-button assignments */
  441. MOUSE_COMPROMISE, /* xterm-ish but with paste on RB in case no MB exists */
  442. MOUSE_XTERM, /* xterm-style: MB pastes, RB extends selection */
  443. MOUSE_WINDOWS /* Windows-style: RB brings up menu. MB still extends. */
  444. };
  445. enum {
  446. /* Function key types (CONF_funky_type) */
  447. FUNKY_TILDE,
  448. FUNKY_LINUX,
  449. FUNKY_XTERM,
  450. FUNKY_VT400,
  451. FUNKY_VT100P,
  452. FUNKY_SCO,
  453. FUNKY_XTERM_216
  454. };
  455. enum {
  456. /* Shifted arrow key types (CONF_sharrow_type) */
  457. SHARROW_APPLICATION, /* Ctrl flips between ESC O A and ESC [ A */
  458. SHARROW_BITMAP /* ESC [ 1 ; n A, where n = 1 + bitmap of CAS */
  459. };
  460. enum {
  461. FQ_DEFAULT, FQ_ANTIALIASED, FQ_NONANTIALIASED, FQ_CLEARTYPE
  462. };
  463. enum {
  464. CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_VERTICAL_LINE
  465. };
  466. enum {
  467. /* these are really bit flags */
  468. BOLD_STYLE_FONT = 1,
  469. BOLD_STYLE_COLOUR = 2,
  470. };
  471. enum {
  472. SER_PAR_NONE, SER_PAR_ODD, SER_PAR_EVEN, SER_PAR_MARK, SER_PAR_SPACE
  473. };
  474. enum {
  475. SER_FLOW_NONE, SER_FLOW_XONXOFF, SER_FLOW_RTSCTS, SER_FLOW_DSRDTR
  476. };
  477. /*
  478. * Tables of string <-> enum value mappings used in settings.c.
  479. * Defined here so that backends can export their GSS library tables
  480. * to the cross-platform settings code.
  481. */
  482. struct keyvalwhere {
  483. /*
  484. * Two fields which define a string and enum value to be
  485. * equivalent to each other.
  486. */
  487. const char *s;
  488. int v;
  489. /*
  490. * The next pair of fields are used by gprefs() in settings.c to
  491. * arrange that when it reads a list of strings representing a
  492. * preference list and translates it into the corresponding list
  493. * of integers, strings not appearing in the list are entered in a
  494. * configurable position rather than uniformly at the end.
  495. */
  496. /*
  497. * 'vrel' indicates which other value in the list to place this
  498. * element relative to. It should be a value that has occurred in
  499. * a 'v' field of some other element of the array, or -1 to
  500. * indicate that we simply place relative to one or other end of
  501. * the list.
  502. *
  503. * gprefs will try to process the elements in an order which makes
  504. * this field work (i.e. so that the element referenced has been
  505. * added before processing this one).
  506. */
  507. int vrel;
  508. /*
  509. * 'where' indicates whether to place the new value before or
  510. * after the one referred to by vrel. -1 means before; +1 means
  511. * after.
  512. *
  513. * When vrel is -1, this also implicitly indicates which end of
  514. * the array to use. So vrel=-1, where=-1 means to place _before_
  515. * some end of the list (hence, at the last element); vrel=-1,
  516. * where=+1 means to place _after_ an end (hence, at the first).
  517. */
  518. int where;
  519. };
  520. #ifndef NO_GSSAPI
  521. extern const int ngsslibs;
  522. extern const char *const gsslibnames[]; /* for displaying in configuration */
  523. extern const struct keyvalwhere gsslibkeywords[]; /* for settings.c */
  524. #endif
  525. extern const char *const ttymodes[];
  526. enum {
  527. /*
  528. * Network address types. Used for specifying choice of IPv4/v6
  529. * in config; also used in proxy.c to indicate whether a given
  530. * host name has already been resolved or will be resolved at
  531. * the proxy end.
  532. */
  533. ADDRTYPE_UNSPEC,
  534. ADDRTYPE_IPV4,
  535. ADDRTYPE_IPV6,
  536. ADDRTYPE_LOCAL, /* e.g. Unix domain socket, or Windows named pipe */
  537. ADDRTYPE_NAME /* SockAddr storing an unresolved host name */
  538. };
  539. /* Backend flags */
  540. #define BACKEND_RESIZE_FORBIDDEN 0x01 /* Backend does not allow
  541. resizing terminal */
  542. #define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
  543. #define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
  544. CONF_ssh_nc_host */
  545. #define BACKEND_NOTIFIES_SESSION_START 0x08 /* Backend will call
  546. seat_notify_session_started */
  547. /* In (no)sshproxy.c */
  548. extern const bool ssh_proxy_supported;
  549. /*
  550. * This structure type wraps a Seat pointer, in a way that has no
  551. * purpose except to be a different type.
  552. *
  553. * The Seat wrapper functions that present interactive prompts all
  554. * expect one of these in place of their ordinary Seat pointer. You
  555. * get one by calling interactor_announce (defined below), which will
  556. * print a message (if not already done) identifying the Interactor
  557. * that originated the prompt.
  558. *
  559. * This arranges that the C type system itself will check that no call
  560. * to any of those Seat methods has omitted the mandatory call to
  561. * interactor_announce beforehand.
  562. */
  563. struct InteractionReadySeat {
  564. Seat *seat;
  565. };
  566. /*
  567. * The Interactor trait is implemented by anything that is capable of
  568. * presenting interactive prompts or questions to the user during
  569. * network connection setup. Every Backend that ever needs to do this
  570. * is an Interactor, but also, while a Backend is making its initial
  571. * network connection, it may go via network proxy code which is also
  572. * an Interactor and can ask questions of its own.
  573. */
  574. struct Interactor {
  575. const InteractorVtable *vt;
  576. /* The parent Interactor that we are a proxy for, if any. */
  577. Interactor *parent;
  578. /*
  579. * If we're the top-level Interactor (parent==NULL), then this
  580. * field records the last Interactor that actually did anything
  581. * interactive, so that we know when to announce a changeover
  582. * between levels of proxying.
  583. *
  584. * If parent != NULL, this field is not used.
  585. */
  586. Interactor *last_to_talk;
  587. };
  588. struct InteractorVtable {
  589. /*
  590. * Returns a user-facing description of the nature of the network
  591. * connection being made. Used in interactive proxy authentication
  592. * to announce which connection attempt is now in control of the
  593. * Seat.
  594. *
  595. * The idea is not just to be written in natural language, but to
  596. * connect with the user's idea of _why_ they think some
  597. * connection is being made. For example, instead of saying 'TCP
  598. * connection to 123.45.67.89 port 22', you might say 'SSH
  599. * connection to [logical host name for SSH host key purposes]'.
  600. *
  601. * The returned string must be freed by the caller.
  602. */
  603. char *(*description)(Interactor *itr);
  604. /*
  605. * Returns the LogPolicy associated with this Interactor. (A
  606. * Backend can derive this from its logging context; a proxy
  607. * Interactor inherits it from the Interactor for the parent
  608. * network connection.)
  609. */
  610. LogPolicy *(*logpolicy)(Interactor *itr);
  611. /*
  612. * Gets and sets the Seat that this Interactor talks to. When a
  613. * Seat is borrowed and replaced with a TempSeat, this will be the
  614. * mechanism by which that replacement happens.
  615. */
  616. Seat *(*get_seat)(Interactor *itr);
  617. void (*set_seat)(Interactor *itr, Seat *seat);
  618. };
  619. static inline char *interactor_description(Interactor *itr)
  620. { return itr->vt->description(itr); }
  621. static inline LogPolicy *interactor_logpolicy(Interactor *itr)
  622. { return itr->vt->logpolicy(itr); }
  623. static inline Seat *interactor_get_seat(Interactor *itr)
  624. { return itr->vt->get_seat(itr); }
  625. static inline void interactor_set_seat(Interactor *itr, Seat *seat)
  626. { itr->vt->set_seat(itr, seat); }
  627. static inline void interactor_set_child(Interactor *parent, Interactor *child)
  628. { child->parent = parent; }
  629. Seat *interactor_borrow_seat(Interactor *itr);
  630. void interactor_return_seat(Interactor *itr);
  631. InteractionReadySeat interactor_announce(Interactor *itr);
  632. /* Interactors that are Backends will find this helper function useful
  633. * in constructing their description strings */
  634. char *default_description(const BackendVtable *backvt,
  635. const char *host, int port);
  636. /*
  637. * The Backend trait is the top-level one that governs each of the
  638. * user-facing main modes that PuTTY can use to talk to some
  639. * destination: SSH, Telnet, serial port, pty, etc.
  640. */
  641. struct Backend {
  642. const BackendVtable *vt;
  643. /* Many Backends are also Interactors. If this one is, a pointer
  644. * to its Interactor trait lives here. */
  645. Interactor *interactor;
  646. };
  647. struct BackendVtable {
  648. char *(*init) (const BackendVtable *vt, Seat *seat,
  649. Backend **backend_out, LogContext *logctx, Conf *conf,
  650. const char *host, int port, char **realhost,
  651. bool nodelay, bool keepalive);
  652. void (*free) (Backend *be);
  653. /* Pass in a replacement configuration. */
  654. void (*reconfig) (Backend *be, Conf *conf);
  655. void (*send) (Backend *be, const char *buf, size_t len);
  656. /* sendbuffer() returns the current amount of buffered data */
  657. size_t (*sendbuffer) (Backend *be);
  658. void (*size) (Backend *be, int width, int height);
  659. void (*special) (Backend *be, SessionSpecialCode code, int arg);
  660. const SessionSpecial *(*get_specials) (Backend *be);
  661. bool (*connected) (Backend *be);
  662. int (*exitcode) (Backend *be);
  663. /* If back->sendok() returns false, the backend doesn't currently
  664. * want input data, so the frontend should avoid acquiring any if
  665. * possible (passing back-pressure on to its sender).
  666. *
  667. * Policy rule: no backend shall return true from sendok() while
  668. * its network connection attempt is still ongoing. This ensures
  669. * that if making the network connection involves a proxy type
  670. * which wants to interact with the user via the terminal, the
  671. * proxy implementation and the backend itself won't fight over
  672. * who gets the terminal input. */
  673. bool (*sendok) (Backend *be);
  674. bool (*ldisc_option_state) (Backend *be, int);
  675. void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
  676. /* Tells the back end that the front end buffer is clearing. */
  677. void (*unthrottle) (Backend *be, size_t bufsize);
  678. int (*cfg_info) (Backend *be);
  679. /* Only implemented in the SSH protocol: check whether a
  680. * connection-sharing upstream exists for a given configuration. */
  681. bool (*test_for_upstream)(const char *host, int port, Conf *conf);
  682. /* Special-purpose function to return additional information to put
  683. * in a "are you sure you want to close this session" dialog;
  684. * return NULL if no such info, otherwise caller must free.
  685. * Only implemented in the SSH protocol, to warn about downstream
  686. * connections that would be lost if this one were terminated. */
  687. char *(*close_warn_text)(Backend *be);
  688. /* 'id' is a machine-readable name for the backend, used in
  689. * saved-session storage. 'displayname_tc' and 'displayname_lc'
  690. * are human-readable names, one in title-case for config boxes,
  691. * and one in lower-case for use in mid-sentence. */
  692. const char *id, *displayname_tc, *displayname_lc;
  693. int protocol;
  694. int default_port;
  695. unsigned flags;
  696. /* Only relevant for the serial protocol: bit masks of which
  697. * parity and flow control settings are supported. */
  698. unsigned serial_parity_mask, serial_flow_mask;
  699. };
  700. static inline char *backend_init(
  701. const BackendVtable *vt, Seat *seat, Backend **out, LogContext *logctx,
  702. Conf *conf, const char *host, int port, char **rhost, bool nd, bool ka)
  703. { return vt->init(vt, seat, out, logctx, conf, host, port, rhost, nd, ka); }
  704. static inline void backend_free(Backend *be)
  705. { be->vt->free(be); }
  706. static inline void backend_reconfig(Backend *be, Conf *conf)
  707. { be->vt->reconfig(be, conf); }
  708. static inline void backend_send(Backend *be, const char *buf, size_t len)
  709. { be->vt->send(be, buf, len); }
  710. static inline size_t backend_sendbuffer(Backend *be)
  711. { return be->vt->sendbuffer(be); }
  712. static inline void backend_size(Backend *be, int width, int height)
  713. { be->vt->size(be, width, height); }
  714. static inline void backend_special(
  715. Backend *be, SessionSpecialCode code, int arg)
  716. { be->vt->special(be, code, arg); }
  717. static inline const SessionSpecial *backend_get_specials(Backend *be)
  718. { return be->vt->get_specials(be); }
  719. static inline bool backend_connected(Backend *be)
  720. { return be->vt->connected(be); }
  721. static inline int backend_exitcode(Backend *be)
  722. { return be->vt->exitcode(be); }
  723. static inline bool backend_sendok(Backend *be)
  724. { return be->vt->sendok(be); }
  725. static inline bool backend_ldisc_option_state(Backend *be, int state)
  726. { return be->vt->ldisc_option_state(be, state); }
  727. static inline void backend_provide_ldisc(Backend *be, Ldisc *ldisc)
  728. { be->vt->provide_ldisc(be, ldisc); }
  729. static inline void backend_unthrottle(Backend *be, size_t bufsize)
  730. { be->vt->unthrottle(be, bufsize); }
  731. static inline int backend_cfg_info(Backend *be)
  732. { return be->vt->cfg_info(be); }
  733. extern const struct BackendVtable *const backends[];
  734. /*
  735. * In programs with a config UI, only the first few members of
  736. * backends[] will be displayed at the top-level; the others will be
  737. * relegated to a drop-down.
  738. */
  739. extern const size_t n_ui_backends;
  740. /*
  741. * Suggested default protocol provided by the backend link module.
  742. * The application is free to ignore this.
  743. */
  744. extern const int be_default_protocol;
  745. /*
  746. * Name of this particular application, for use in the config box
  747. * and other pieces of text.
  748. */
  749. extern const char *const appname;
  750. /*
  751. * Used by callback.c; declared up here so that prompts_t can use it
  752. */
  753. typedef void (*toplevel_callback_fn_t)(void *ctx);
  754. /* Enum of result types in SeatPromptResult below */
  755. typedef enum SeatPromptResultKind {
  756. /* Answer not yet available at all; either try again later or wait
  757. * for a callback (depending on the request's API) */
  758. SPRK_INCOMPLETE,
  759. /* We're abandoning the connection because the user interactively
  760. * told us to. (Hence, no need to present an error message
  761. * telling the user we're doing that: they already know.) */
  762. SPRK_USER_ABORT,
  763. /* We're abandoning the connection for some other reason (e.g. we
  764. * were unable to present the prompt at all, or a batch-mode
  765. * configuration told us to give the answer no). This may
  766. * ultimately have stemmed from some user configuration, but they
  767. * didn't _tell us right now_ to abandon this connection, so we
  768. * still need to inform them that we've done so. */
  769. SPRK_SW_ABORT,
  770. /* We're proceeding with the connection and have all requested
  771. * information (if any) */
  772. SPRK_OK
  773. } SeatPromptResultKind;
  774. /* Small struct to present the results of interactive requests from
  775. * backend to Seat (see below) */
  776. struct SeatPromptResult {
  777. SeatPromptResultKind kind;
  778. /*
  779. * In the case of SPRK_SW_ABORT, the frontend provides an error
  780. * message to present to the user. But dynamically allocating it
  781. * up front would mean having to make sure it got freed at any
  782. * call site where one of these structs is received (and freed
  783. * _once_ no matter how many times the struct is copied). So
  784. * instead we provide a function that will generate the error
  785. * message into a BinarySink.
  786. */
  787. void (*errfn)(SeatPromptResult, BinarySink *);
  788. /*
  789. * And some fields the error function can use to construct the
  790. * message (holding, e.g. an OS error code).
  791. */
  792. const char *errdata_lit; /* statically allocated, e.g. a string literal */
  793. unsigned errdata_u;
  794. };
  795. /* Helper function to construct the simple versions of these
  796. * structures inline */
  797. static inline SeatPromptResult make_spr_simple(SeatPromptResultKind kind)
  798. {
  799. SeatPromptResult spr;
  800. spr.kind = kind;
  801. spr.errdata_lit = NULL;
  802. return spr;
  803. }
  804. /* Most common constructor function for SPRK_SW_ABORT errors */
  805. SeatPromptResult make_spr_sw_abort_static(const char *);
  806. /* Convenience macros wrapping those constructors in turn */
  807. #define SPR_INCOMPLETE make_spr_simple(SPRK_INCOMPLETE)
  808. #define SPR_USER_ABORT make_spr_simple(SPRK_USER_ABORT)
  809. #define SPR_SW_ABORT(lit) make_spr_sw_abort_static(lit)
  810. #define SPR_OK make_spr_simple(SPRK_OK)
  811. /* Query function that folds both kinds of abort together */
  812. static inline bool spr_is_abort(SeatPromptResult spr)
  813. {
  814. return spr.kind == SPRK_USER_ABORT || spr.kind == SPRK_SW_ABORT;
  815. }
  816. /* Function to return a dynamically allocated copy of the error message */
  817. char *spr_get_error_message(SeatPromptResult spr);
  818. /*
  819. * Mechanism for getting text strings such as usernames and passwords
  820. * from the front-end.
  821. * The fields are mostly modelled after SSH's keyboard-interactive auth.
  822. * FIXME We should probably mandate a character set/encoding (probably UTF-8).
  823. *
  824. * Since many of the pieces of text involved may be chosen by the server,
  825. * the caller must take care to ensure that the server can't spoof locally-
  826. * generated prompts such as key passphrase prompts. Some ground rules:
  827. * - If the front-end needs to truncate a string, it should lop off the
  828. * end.
  829. * - The front-end should filter out any dangerous characters and
  830. * generally not trust the strings. (But \n is required to behave
  831. * vaguely sensibly, at least in `instruction', and ideally in
  832. * `prompt[]' too.)
  833. */
  834. typedef struct {
  835. char *prompt;
  836. bool echo;
  837. strbuf *result;
  838. } prompt_t;
  839. typedef struct prompts_t prompts_t;
  840. struct prompts_t {
  841. /*
  842. * Indicates whether the information entered is to be used locally
  843. * (for instance a key passphrase prompt), or is destined for the wire.
  844. * This is a hint only; the front-end is at liberty not to use this
  845. * information (so the caller should ensure that the supplied text is
  846. * sufficient).
  847. */
  848. bool to_server;
  849. /*
  850. * Indicates whether the prompts originated _at_ the server, so
  851. * that the front end can display some kind of trust sigil that
  852. * distinguishes (say) a legit private-key passphrase prompt from
  853. * a fake one sent by a malicious server.
  854. */
  855. bool from_server;
  856. char *name; /* Short description, perhaps for dialog box title */
  857. bool name_reqd; /* Display of `name' required or optional? */
  858. char *instruction; /* Long description, maybe with embedded newlines */
  859. bool instr_reqd; /* Display of `instruction' required or optional? */
  860. size_t n_prompts; /* May be zero (in which case display the foregoing,
  861. * if any, and return success) */
  862. size_t prompts_size; /* allocated storage capacity for prompts[] */
  863. prompt_t **prompts;
  864. void *data; /* slot for housekeeping data, managed by
  865. * seat_get_userpass_input(); initially NULL */
  866. SeatPromptResult spr; /* some implementations need to cache one of these */
  867. /*
  868. * Set this flag to indicate that the caller has encoded the
  869. * prompts in UTF-8, and expects the responses to be UTF-8 too.
  870. *
  871. * Ideally this flag would be unnecessary because it would always
  872. * be true, but for legacy reasons, we have to switch over a bit
  873. * at a time from the old behaviour, and may never manage to get
  874. * rid of it completely.
  875. */
  876. bool utf8;
  877. /*
  878. * Callback you can fill in to be notified when all the prompts'
  879. * responses are available. After you receive this notification, a
  880. * further call to the get_userpass_input function will return the
  881. * final state of the prompts system, which is guaranteed not to
  882. * be negative for 'still ongoing'.
  883. */
  884. toplevel_callback_fn_t callback;
  885. void *callback_ctx;
  886. /*
  887. * When this prompts_t is known to an Ldisc, we might need to
  888. * break the connection if things get freed in an emergency. So
  889. * this is a pointer to the Ldisc's pointer to us.
  890. */
  891. prompts_t **ldisc_ptr_to_us;
  892. };
  893. prompts_t *new_prompts(void);
  894. void add_prompt(prompts_t *p, char *promptstr, bool echo);
  895. void prompt_set_result(prompt_t *pr, const char *newstr);
  896. char *prompt_get_result(prompt_t *pr);
  897. const char *prompt_get_result_ref(prompt_t *pr);
  898. void free_prompts(prompts_t *p);
  899. /*
  900. * Data type definitions for true-colour terminal display.
  901. * 'optionalrgb' describes a single RGB colour, which overrides the
  902. * other colour settings if 'enabled' is nonzero, and is ignored
  903. * otherwise. 'truecolour' contains a pair of those for foreground and
  904. * background.
  905. */
  906. typedef struct optionalrgb {
  907. bool enabled;
  908. unsigned char r, g, b;
  909. } optionalrgb;
  910. extern const optionalrgb optionalrgb_none;
  911. typedef struct truecolour {
  912. optionalrgb fg, bg;
  913. } truecolour;
  914. #define optionalrgb_equal(r1,r2) ( \
  915. (r1).enabled==(r2).enabled && \
  916. (r1).r==(r2).r && (r1).g==(r2).g && (r1).b==(r2).b)
  917. #define truecolour_equal(c1,c2) ( \
  918. optionalrgb_equal((c1).fg, (c2).fg) && \
  919. optionalrgb_equal((c1).bg, (c2).bg))
  920. /*
  921. * Enumeration of clipboards. We provide some standard ones cross-
  922. * platform, and then permit each platform to extend this enumeration
  923. * further by defining PLATFORM_CLIPBOARDS in its own header file.
  924. *
  925. * CLIP_NULL is a non-clipboard, writes to which are ignored and reads
  926. * from which return no data.
  927. *
  928. * CLIP_LOCAL refers to a buffer within terminal.c, which
  929. * unconditionally saves the last data selected in the terminal. In
  930. * configurations where a system clipboard is not written
  931. * automatically on selection but instead by an explicit UI action,
  932. * this is where the code responding to that action can find the data
  933. * to write to the clipboard in question.
  934. */
  935. #define CROSS_PLATFORM_CLIPBOARDS(X) \
  936. X(CLIP_NULL, "null clipboard") \
  937. X(CLIP_LOCAL, "last text selected in terminal") \
  938. /* end of list */
  939. #define ALL_CLIPBOARDS(X) \
  940. CROSS_PLATFORM_CLIPBOARDS(X) \
  941. PLATFORM_CLIPBOARDS(X) \
  942. /* end of list */
  943. #define CLIP_ID(id,name) id,
  944. enum { ALL_CLIPBOARDS(CLIP_ID) N_CLIPBOARDS };
  945. #undef CLIP_ID
  946. /* Hint from backend to frontend about time-consuming operations, used
  947. * by seat_set_busy_status. Initial state is assumed to be
  948. * BUSY_NOT. */
  949. typedef enum BusyStatus {
  950. BUSY_NOT, /* Not busy, all user interaction OK */
  951. BUSY_WAITING, /* Waiting for something; local event loops still
  952. running so some local interaction (e.g. menus)
  953. OK, but network stuff is suspended */
  954. BUSY_CPU /* Locally busy (e.g. crypto); user interaction
  955. * suspended */
  956. } BusyStatus;
  957. typedef enum SeatInteractionContext {
  958. SIC_BANNER, SIC_KI_PROMPTS
  959. } SeatInteractionContext;
  960. typedef enum SeatOutputType {
  961. SEAT_OUTPUT_STDOUT, SEAT_OUTPUT_STDERR
  962. } SeatOutputType;
  963. typedef enum SeatDialogTextType {
  964. SDT_PARA, SDT_DISPLAY, SDT_SCARY_HEADING,
  965. SDT_TITLE, SDT_PROMPT, SDT_BATCH_ABORT,
  966. SDT_MORE_INFO_KEY, SDT_MORE_INFO_VALUE_SHORT, SDT_MORE_INFO_VALUE_BLOB
  967. } SeatDialogTextType;
  968. struct SeatDialogTextItem {
  969. SeatDialogTextType type;
  970. char *text;
  971. };
  972. struct SeatDialogText {
  973. size_t nitems, itemsize;
  974. SeatDialogTextItem *items;
  975. };
  976. SeatDialogText *seat_dialog_text_new(void);
  977. void seat_dialog_text_free(SeatDialogText *sdt);
  978. PRINTF_LIKE(3, 4) void seat_dialog_text_append(
  979. SeatDialogText *sdt, SeatDialogTextType type, const char *fmt, ...);
  980. /*
  981. * Data type 'Seat', which is an API intended to contain essentially
  982. * everything that a back end might need to talk to its client for:
  983. * session output, password prompts, SSH warnings about host keys and
  984. * weak cryptography, notifications of events like the remote process
  985. * exiting or the GUI specials menu needing an update.
  986. */
  987. struct Seat {
  988. const struct SeatVtable *vt;
  989. };
  990. struct SeatVtable {
  991. /*
  992. * Provide output from the remote session. 'type' indicates the
  993. * type of the output (stdout or stderr), which can be used to
  994. * split the output into separate message channels, if the seat
  995. * wants to handle them differently. But combining the channels
  996. * into one is OK too; that's what terminal-window based seats do.
  997. *
  998. * The return value is the current size of the output backlog.
  999. */
  1000. size_t (*output)(Seat *seat, SeatOutputType type,
  1001. const void *data, size_t len);
  1002. /*
  1003. * Called when the back end wants to indicate that EOF has arrived
  1004. * on the server-to-client stream. Returns false to indicate that
  1005. * we intend to keep the session open in the other direction, or
  1006. * true to indicate that if they're closing so are we.
  1007. */
  1008. bool (*eof)(Seat *seat);
  1009. /*
  1010. * Called by the back end to notify that the output backlog has
  1011. * changed size. A front end in control of the event loop won't
  1012. * necessarily need this (they can just keep checking it via
  1013. * backend_sendbuffer at every opportunity), but one buried in the
  1014. * depths of something else (like an SSH proxy) will need to be
  1015. * proactively notified that the amount of buffered data has
  1016. * become smaller.
  1017. */
  1018. void (*sent)(Seat *seat, size_t new_sendbuffer);
  1019. /*
  1020. * Provide authentication-banner output from the session setup.
  1021. * End-user Seats can treat this as very similar to 'output', but
  1022. * intermediate Seats in complex proxying situations will want to
  1023. * implement this and 'output' differently.
  1024. */
  1025. size_t (*banner)(Seat *seat, const void *data, size_t len);
  1026. /*
  1027. * Try to get answers from a set of interactive login prompts. The
  1028. * prompts are provided in 'p'.
  1029. *
  1030. * (FIXME: it would be nice to distinguish two classes of user-
  1031. * abort action, so the user could specify 'I want to abandon this
  1032. * entire attempt to start a session' or the milder 'I want to
  1033. * abandon this particular form of authentication and fall back to
  1034. * a different one' - e.g. if you turn out not to be able to
  1035. * remember your private key passphrase then perhaps you'd rather
  1036. * fall back to password auth rather than aborting the whole
  1037. * session.)
  1038. */
  1039. SeatPromptResult (*get_userpass_input)(Seat *seat, prompts_t *p);
  1040. /*
  1041. * Notify the seat that the main session channel has been
  1042. * successfully set up.
  1043. *
  1044. * This is only used as part of the SSH proxying system, so it's
  1045. * not necessary to implement it in all backends. A backend must
  1046. * call this if it advertises the BACKEND_NOTIFIES_SESSION_START
  1047. * flag, and otherwise, doesn't have to.
  1048. */
  1049. void (*notify_session_started)(Seat *seat);
  1050. /*
  1051. * Notify the seat that the process running at the other end of
  1052. * the connection has finished.
  1053. */
  1054. void (*notify_remote_exit)(Seat *seat);
  1055. /*
  1056. * Notify the seat that the whole connection has finished.
  1057. * (Distinct from notify_remote_exit, e.g. in the case where you
  1058. * have port forwardings still active when the main foreground
  1059. * session goes away: then you'd get notify_remote_exit when the
  1060. * foreground session dies, but notify_remote_disconnect when the
  1061. * last forwarding vanishes and the network connection actually
  1062. * closes.)
  1063. *
  1064. * This function might be called multiple times by accident; seats
  1065. * should be prepared to cope.
  1066. *
  1067. * More precisely: this function notifies the seat that
  1068. * backend_connected() might now return false where previously it
  1069. * returned true. (Note the 'might': an accidental duplicate call
  1070. * might happen when backend_connected() was already returning
  1071. * false. Or even, in weird situations, when it hadn't stopped
  1072. * returning true yet. The point is, when you get this
  1073. * notification, all it's really telling you is that it's worth
  1074. * _checking_ backend_connected, if you weren't already.)
  1075. */
  1076. void (*notify_remote_disconnect)(Seat *seat);
  1077. /*
  1078. * Notify the seat that the connection has suffered an error,
  1079. * either fatal to the whole connection or not.
  1080. *
  1081. * The latter kind of error is expected to be things along the
  1082. * lines of 'I/O error storing the new host key', which has
  1083. * traditionally been presented via a dialog box or similar.
  1084. */
  1085. void (*connection_fatal)(Seat *seat, const char *message);
  1086. void (*nonfatal)(Seat *seat, const char *message);
  1087. /*
  1088. * Notify the seat that the list of special commands available
  1089. * from backend_get_specials() has changed, so that it might want
  1090. * to call that function to repopulate its menu.
  1091. *
  1092. * Seats are not expected to call backend_get_specials()
  1093. * proactively; they may start by assuming that the backend
  1094. * provides no special commands at all, so if the backend does
  1095. * provide any, then it should use this notification at startup
  1096. * time. Of course it can also invoke it later if the set of
  1097. * special commands changes.
  1098. *
  1099. * It does not need to invoke it at session shutdown.
  1100. */
  1101. void (*update_specials_menu)(Seat *seat);
  1102. /*
  1103. * Get the seat's preferred value for an SSH terminal mode
  1104. * setting. Returning NULL indicates no preference (i.e. the SSH
  1105. * connection will not attempt to set the mode at all).
  1106. *
  1107. * The returned value is dynamically allocated, and the caller
  1108. * should free it.
  1109. */
  1110. char *(*get_ttymode)(Seat *seat, const char *mode);
  1111. /*
  1112. * Tell the seat whether the backend is currently doing anything
  1113. * CPU-intensive (typically a cryptographic key exchange). See
  1114. * BusyStatus enumeration above.
  1115. */
  1116. void (*set_busy_status)(Seat *seat, BusyStatus status);
  1117. /*
  1118. * Ask the seat whether a given SSH host key should be accepted.
  1119. * This is called after we've already checked it by any means we
  1120. * can do ourselves, such as checking against host key
  1121. * fingerprints in the Conf or the host key cache on disk: once we
  1122. * call this function, we've already decided there's nothing for
  1123. * it but to prompt the user.
  1124. *
  1125. * 'mismatch' reports the result of checking the host key cache:
  1126. * it is true if the server has presented a host key different
  1127. * from the one we expected, and false if we had no expectation in
  1128. * the first place.
  1129. *
  1130. * This call may prompt the user synchronously and not return
  1131. * until the answer is available, or it may present the prompt and
  1132. * return immediately, giving the answer later via the provided
  1133. * callback.
  1134. *
  1135. * Return values:
  1136. *
  1137. * - +1 means `user approved the key, so continue with the
  1138. * connection'
  1139. *
  1140. * - 0 means `user rejected the key, abandon the connection'
  1141. *
  1142. * - -1 means `I've initiated enquiries, please wait to be called
  1143. * back via the provided function with a result that's either 0
  1144. * or +1'.
  1145. */
  1146. SeatPromptResult (*confirm_ssh_host_key)(
  1147. Seat *seat, const char *host, int port, const char *keytype,
  1148. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1149. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1150. /*
  1151. * Check with the seat whether it's OK to use a cryptographic
  1152. * primitive from below the 'warn below this line' threshold in
  1153. * the input Conf. Return values are the same as
  1154. * confirm_ssh_host_key above.
  1155. */
  1156. SeatPromptResult (*confirm_weak_crypto_primitive)(
  1157. Seat *seat, SeatDialogText *text,
  1158. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1159. /*
  1160. * Variant form of confirm_weak_crypto_primitive, which prints a
  1161. * slightly different message but otherwise has the same
  1162. * semantics.
  1163. *
  1164. * This form is used in the case where we're using a host key
  1165. * below the warning threshold because that's the best one we have
  1166. * cached, but at least one host key algorithm *above* the
  1167. * threshold is available that we don't have cached.
  1168. */
  1169. SeatPromptResult (*confirm_weak_cached_hostkey)(
  1170. Seat *seat, SeatDialogText *text,
  1171. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1172. /*
  1173. * Some snippets of text describing the UI actions in host key
  1174. * prompts / dialog boxes, to be used in ssh/common.c when it
  1175. * assembles the full text of those prompts.
  1176. */
  1177. const SeatDialogPromptDescriptions *(*prompt_descriptions)(Seat *seat);
  1178. /*
  1179. * Indicates whether the seat is expecting to interact with the
  1180. * user in the UTF-8 character set. (Affects e.g. visual erase
  1181. * handling in local line editing.)
  1182. */
  1183. bool (*is_utf8)(Seat *seat);
  1184. /*
  1185. * Notify the seat that the back end, and/or the ldisc between
  1186. * them, have changed their idea of whether they currently want
  1187. * local echo and/or local line editing enabled.
  1188. */
  1189. void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
  1190. /*
  1191. * Return the local X display string relevant to a seat, or NULL
  1192. * if there isn't one or if the concept is meaningless.
  1193. */
  1194. const char *(*get_x_display)(Seat *seat);
  1195. /*
  1196. * Return the X11 id of the X terminal window relevant to a seat,
  1197. * by returning true and filling in the output pointer. Return
  1198. * false if there isn't one or if the concept is meaningless.
  1199. */
  1200. bool (*get_windowid)(Seat *seat, long *id_out);
  1201. /*
  1202. * Return the size of the terminal window in pixels. If the
  1203. * concept is meaningless or the information is unavailable,
  1204. * return false; otherwise fill in the output pointers and return
  1205. * true.
  1206. */
  1207. bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
  1208. /*
  1209. * Return a StripCtrlChars appropriate for sanitising untrusted
  1210. * terminal data (e.g. SSH banners, prompts) being sent to the
  1211. * user of this seat. May return NULL if no sanitisation is
  1212. * needed.
  1213. */
  1214. StripCtrlChars *(*stripctrl_new)(
  1215. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1216. /*
  1217. * Set the seat's current idea of where output is coming from.
  1218. * True means that output is being generated by our own code base
  1219. * (and hence, can be trusted if it's asking you for secrets such
  1220. * as your passphrase); false means output is coming from the
  1221. * server.
  1222. */
  1223. void (*set_trust_status)(Seat *seat, bool trusted);
  1224. /*
  1225. * Query whether this Seat can do anything user-visible in
  1226. * response to set_trust_status.
  1227. *
  1228. * Returns true if the seat has a way to indicate this
  1229. * distinction. Returns false if not, in which case the backend
  1230. * should use a fallback defence against spoofing of PuTTY's local
  1231. * prompts by malicious servers.
  1232. */
  1233. bool (*can_set_trust_status)(Seat *seat);
  1234. /*
  1235. * Query whether this Seat's interactive prompt responses and its
  1236. * session input come from the same place.
  1237. *
  1238. * If false, this is used to suppress the final 'Press Return to
  1239. * begin session' anti-spoofing prompt in Plink. For example,
  1240. * Plink itself sets this flag if its standard input is redirected
  1241. * (and therefore not coming from the same place as the console
  1242. * it's sending its prompts to).
  1243. */
  1244. bool (*has_mixed_input_stream)(Seat *seat);
  1245. /*
  1246. * Ask the seat whether it would like verbose messages.
  1247. */
  1248. bool (*verbose)(Seat *seat);
  1249. /*
  1250. * Ask the seat whether it's an interactive program.
  1251. */
  1252. bool (*interactive)(Seat *seat);
  1253. /*
  1254. * Return the seat's current idea of where the output cursor is.
  1255. *
  1256. * Returns true if the seat has a cursor. Returns false if not.
  1257. */
  1258. bool (*get_cursor_position)(Seat *seat, int *x, int *y);
  1259. };
  1260. static inline size_t seat_output(
  1261. Seat *seat, SeatOutputType type, const void *data, size_t len)
  1262. { return seat->vt->output(seat, type, data, len); }
  1263. static inline bool seat_eof(Seat *seat)
  1264. { return seat->vt->eof(seat); }
  1265. static inline void seat_sent(Seat *seat, size_t bufsize)
  1266. { seat->vt->sent(seat, bufsize); }
  1267. static inline size_t seat_banner(
  1268. InteractionReadySeat iseat, const void *data, size_t len)
  1269. { return iseat.seat->vt->banner(iseat.seat, data, len); }
  1270. static inline SeatPromptResult seat_get_userpass_input(
  1271. InteractionReadySeat iseat, prompts_t *p)
  1272. { return iseat.seat->vt->get_userpass_input(iseat.seat, p); }
  1273. static inline void seat_notify_session_started(Seat *seat)
  1274. { seat->vt->notify_session_started(seat); }
  1275. static inline void seat_notify_remote_exit(Seat *seat)
  1276. { seat->vt->notify_remote_exit(seat); }
  1277. static inline void seat_notify_remote_disconnect(Seat *seat)
  1278. { seat->vt->notify_remote_disconnect(seat); }
  1279. static inline void seat_update_specials_menu(Seat *seat)
  1280. { seat->vt->update_specials_menu(seat); }
  1281. static inline char *seat_get_ttymode(Seat *seat, const char *mode)
  1282. { return seat->vt->get_ttymode(seat, mode); }
  1283. static inline void seat_set_busy_status(Seat *seat, BusyStatus status)
  1284. { seat->vt->set_busy_status(seat, status); }
  1285. static inline SeatPromptResult seat_confirm_ssh_host_key(
  1286. InteractionReadySeat iseat, const char *h, int p, const char *ktyp,
  1287. char *kstr, SeatDialogText *text, HelpCtx helpctx,
  1288. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1289. { return iseat.seat->vt->confirm_ssh_host_key(
  1290. iseat.seat, h, p, ktyp, kstr, text, helpctx, cb, ctx); }
  1291. static inline SeatPromptResult seat_confirm_weak_crypto_primitive(
  1292. InteractionReadySeat iseat, SeatDialogText *text,
  1293. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1294. { return iseat.seat->vt->confirm_weak_crypto_primitive(
  1295. iseat.seat, text, cb, ctx); }
  1296. static inline SeatPromptResult seat_confirm_weak_cached_hostkey(
  1297. InteractionReadySeat iseat, SeatDialogText *text,
  1298. void (*cb)(void *ctx, SeatPromptResult result), void *ctx)
  1299. { return iseat.seat->vt->confirm_weak_cached_hostkey(
  1300. iseat.seat, text, cb, ctx); }
  1301. static inline const SeatDialogPromptDescriptions *seat_prompt_descriptions(
  1302. Seat *seat)
  1303. { return seat->vt->prompt_descriptions(seat); }
  1304. static inline bool seat_is_utf8(Seat *seat)
  1305. { return seat->vt->is_utf8(seat); }
  1306. static inline void seat_echoedit_update(Seat *seat, bool ec, bool ed)
  1307. { seat->vt->echoedit_update(seat, ec, ed); }
  1308. static inline const char *seat_get_x_display(Seat *seat)
  1309. { return seat->vt->get_x_display(seat); }
  1310. static inline bool seat_get_windowid(Seat *seat, long *id_out)
  1311. { return seat->vt->get_windowid(seat, id_out); }
  1312. static inline bool seat_get_window_pixel_size(Seat *seat, int *w, int *h)
  1313. { return seat->vt->get_window_pixel_size(seat, w, h); }
  1314. static inline StripCtrlChars *seat_stripctrl_new(
  1315. Seat *seat, BinarySink *bs, SeatInteractionContext sic)
  1316. { return seat->vt->stripctrl_new(seat, bs, sic); }
  1317. static inline void seat_set_trust_status(Seat *seat, bool trusted)
  1318. { seat->vt->set_trust_status(seat, trusted); }
  1319. static inline bool seat_can_set_trust_status(Seat *seat)
  1320. { return seat->vt->can_set_trust_status(seat); }
  1321. static inline bool seat_has_mixed_input_stream(Seat *seat)
  1322. { return seat->vt->has_mixed_input_stream(seat); }
  1323. static inline bool seat_verbose(Seat *seat)
  1324. { return seat->vt->verbose(seat); }
  1325. static inline bool seat_interactive(Seat *seat)
  1326. { return seat->vt->interactive(seat); }
  1327. static inline bool seat_get_cursor_position(Seat *seat, int *x, int *y)
  1328. { return seat->vt->get_cursor_position(seat, x, y); }
  1329. /* Unlike the seat's actual method, the public entry points
  1330. * seat_connection_fatal and seat_nonfatal are wrapper functions with
  1331. * a printf-like API, defined in utils. */
  1332. void seat_connection_fatal(Seat *seat, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1333. void seat_nonfatal(Seat *seat, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1334. /* Handy aliases for seat_output which set is_stderr to a fixed value. */
  1335. static inline size_t seat_stdout(Seat *seat, const void *data, size_t len)
  1336. { return seat_output(seat, SEAT_OUTPUT_STDOUT, data, len); }
  1337. static inline size_t seat_stdout_pl(Seat *seat, ptrlen data)
  1338. { return seat_output(seat, SEAT_OUTPUT_STDOUT, data.ptr, data.len); }
  1339. static inline size_t seat_stderr(Seat *seat, const void *data, size_t len)
  1340. { return seat_output(seat, SEAT_OUTPUT_STDERR, data, len); }
  1341. static inline size_t seat_stderr_pl(Seat *seat, ptrlen data)
  1342. { return seat_output(seat, SEAT_OUTPUT_STDERR, data.ptr, data.len); }
  1343. /* Alternative API for seat_banner taking a ptrlen */
  1344. static inline size_t seat_banner_pl(InteractionReadySeat iseat, ptrlen data)
  1345. { return iseat.seat->vt->banner(iseat.seat, data.ptr, data.len); }
  1346. struct SeatDialogPromptDescriptions {
  1347. const char *hk_accept_action;
  1348. const char *hk_connect_once_action;
  1349. const char *hk_cancel_action, *hk_cancel_action_Participle;
  1350. const char *weak_accept_action, *weak_cancel_action;
  1351. };
  1352. /* In the utils subdir: print a message to the Seat which can't be
  1353. * spoofed by server-supplied auth-time output such as SSH banners */
  1354. void seat_antispoof_msg(InteractionReadySeat iseat, const char *msg);
  1355. /*
  1356. * Stub methods for seat implementations that want to use the obvious
  1357. * null handling for a given method.
  1358. *
  1359. * These are generally obvious, except for is_utf8, where you might
  1360. * plausibly want to return either fixed answer 'no' or 'yes'.
  1361. */
  1362. size_t nullseat_output(
  1363. Seat *seat, SeatOutputType type, const void *data, size_t len);
  1364. bool nullseat_eof(Seat *seat);
  1365. void nullseat_sent(Seat *seat, size_t bufsize);
  1366. size_t nullseat_banner(Seat *seat, const void *data, size_t len);
  1367. size_t nullseat_banner_to_stderr(Seat *seat, const void *data, size_t len);
  1368. SeatPromptResult nullseat_get_userpass_input(Seat *seat, prompts_t *p);
  1369. void nullseat_notify_session_started(Seat *seat);
  1370. void nullseat_notify_remote_exit(Seat *seat);
  1371. void nullseat_notify_remote_disconnect(Seat *seat);
  1372. void nullseat_connection_fatal(Seat *seat, const char *message);
  1373. void nullseat_nonfatal(Seat *seat, const char *message);
  1374. void nullseat_update_specials_menu(Seat *seat);
  1375. char *nullseat_get_ttymode(Seat *seat, const char *mode);
  1376. void nullseat_set_busy_status(Seat *seat, BusyStatus status);
  1377. SeatPromptResult nullseat_confirm_ssh_host_key(
  1378. Seat *seat, const char *host, int port, const char *keytype,
  1379. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1380. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1381. SeatPromptResult nullseat_confirm_weak_crypto_primitive(
  1382. Seat *seat, SeatDialogText *text,
  1383. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1384. SeatPromptResult nullseat_confirm_weak_cached_hostkey(
  1385. Seat *seat, SeatDialogText *text,
  1386. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1387. const SeatDialogPromptDescriptions *nullseat_prompt_descriptions(Seat *seat);
  1388. bool nullseat_is_never_utf8(Seat *seat);
  1389. bool nullseat_is_always_utf8(Seat *seat);
  1390. void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
  1391. const char *nullseat_get_x_display(Seat *seat);
  1392. bool nullseat_get_windowid(Seat *seat, long *id_out);
  1393. bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
  1394. StripCtrlChars *nullseat_stripctrl_new(
  1395. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1396. void nullseat_set_trust_status(Seat *seat, bool trusted);
  1397. bool nullseat_can_set_trust_status_yes(Seat *seat);
  1398. bool nullseat_can_set_trust_status_no(Seat *seat);
  1399. bool nullseat_has_mixed_input_stream_yes(Seat *seat);
  1400. bool nullseat_has_mixed_input_stream_no(Seat *seat);
  1401. bool nullseat_verbose_no(Seat *seat);
  1402. bool nullseat_verbose_yes(Seat *seat);
  1403. bool nullseat_interactive_no(Seat *seat);
  1404. bool nullseat_interactive_yes(Seat *seat);
  1405. bool nullseat_get_cursor_position(Seat *seat, int *x, int *y);
  1406. /*
  1407. * Seat functions provided by the platform's console-application
  1408. * support module (console.c in each platform subdirectory).
  1409. */
  1410. void console_connection_fatal(Seat *seat, const char *message);
  1411. void console_nonfatal(Seat *seat, const char *message);
  1412. SeatPromptResult console_confirm_ssh_host_key(
  1413. Seat *seat, const char *host, int port, const char *keytype,
  1414. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  1415. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1416. SeatPromptResult console_confirm_weak_crypto_primitive(
  1417. Seat *seat, SeatDialogText *text,
  1418. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1419. SeatPromptResult console_confirm_weak_cached_hostkey(
  1420. Seat *seat, SeatDialogText *text,
  1421. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  1422. StripCtrlChars *console_stripctrl_new(
  1423. Seat *seat, BinarySink *bs_out, SeatInteractionContext sic);
  1424. void console_set_trust_status(Seat *seat, bool trusted);
  1425. bool console_can_set_trust_status(Seat *seat);
  1426. bool console_has_mixed_input_stream(Seat *seat);
  1427. const SeatDialogPromptDescriptions *console_prompt_descriptions(Seat *seat);
  1428. /*
  1429. * Other centralised seat functions.
  1430. */
  1431. SeatPromptResult filexfer_get_userpass_input(Seat *seat, prompts_t *p);
  1432. bool cmdline_seat_verbose(Seat *seat);
  1433. /*
  1434. * TempSeat: a seat implementation that can be given to a backend
  1435. * temporarily while network proxy setup is using the real seat.
  1436. * Buffers output and trust-status changes until the real seat is
  1437. * available again.
  1438. */
  1439. /* Called by the proxy code to make a TempSeat. */
  1440. Seat *tempseat_new(Seat *real);
  1441. /* Query functions to tell if a Seat _is_ temporary, and if so, to
  1442. * return the underlying real Seat. */
  1443. bool is_tempseat(Seat *seat);
  1444. Seat *tempseat_get_real(Seat *seat);
  1445. /* Called by interactor_return_seat once the proxy connection has
  1446. * finished setting up (or failed), to pass on any buffered stuff to
  1447. * the real seat. */
  1448. void tempseat_flush(Seat *ts);
  1449. /* Frees a TempSeat, without flushing anything it has buffered. (Call
  1450. * this after tempseat_flush, or alternatively, when you were going to
  1451. * abandon the whole connection anyway.) */
  1452. void tempseat_free(Seat *ts);
  1453. typedef struct rgb {
  1454. uint8_t r, g, b;
  1455. } rgb;
  1456. /*
  1457. * Data type 'TermWin', which is a vtable encapsulating all the
  1458. * functionality that Terminal expects from its containing terminal
  1459. * window.
  1460. */
  1461. struct TermWin {
  1462. const struct TermWinVtable *vt;
  1463. };
  1464. struct TermWinVtable {
  1465. /*
  1466. * All functions listed here between setup_draw_ctx and
  1467. * free_draw_ctx expect to be _called_ between them too, so that
  1468. * the TermWin has a drawing context currently available.
  1469. *
  1470. * (Yes, even char_width, because e.g. the Windows implementation
  1471. * of TermWin handles it by loading the currently configured font
  1472. * into the HDC and doing a GDI query.)
  1473. */
  1474. bool (*setup_draw_ctx)(TermWin *);
  1475. /* Draw text in the window, during a painting operation */
  1476. void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
  1477. unsigned long attrs, int line_attrs, truecolour tc);
  1478. /* Draw the visible cursor. Expects you to have called do_text
  1479. * first (because it might just draw an underline over a character
  1480. * presumed to exist already), but also expects you to pass in all
  1481. * the details of the character under the cursor (because it might
  1482. * redraw it in different colours). */
  1483. void (*draw_cursor)(TermWin *, int x, int y, wchar_t *text, int len,
  1484. unsigned long attrs, int line_attrs, truecolour tc);
  1485. /* Draw the sigil indicating that a line of text has come from
  1486. * PuTTY itself rather than the far end (defence against end-of-
  1487. * authentication spoofing) */
  1488. void (*draw_trust_sigil)(TermWin *, int x, int y);
  1489. int (*char_width)(TermWin *, int uc);
  1490. void (*free_draw_ctx)(TermWin *);
  1491. void (*set_cursor_pos)(TermWin *, int x, int y);
  1492. /* set_raw_mouse_mode instructs the front end to start sending mouse events
  1493. * in raw mode suitable for translating into mouse-tracking terminal data
  1494. * (e.g. include scroll-wheel events and don't bother to identify double-
  1495. * and triple-clicks). set_raw_mouse_mode_pointer instructs the front end
  1496. * to change the mouse pointer shape to *indicate* raw mouse mode. */
  1497. void (*set_raw_mouse_mode)(TermWin *, bool enable);
  1498. void (*set_raw_mouse_mode_pointer)(TermWin *, bool enable);
  1499. void (*set_scrollbar)(TermWin *, int total, int start, int page);
  1500. void (*bell)(TermWin *, int mode);
  1501. void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
  1502. truecolour *colours, int len, bool must_deselect);
  1503. void (*clip_request_paste)(TermWin *, int clipboard);
  1504. void (*refresh)(TermWin *);
  1505. /* request_resize asks the front end if the terminal can please be
  1506. * resized to (w,h) in characters. The front end MAY call
  1507. * term_size() in response to tell the terminal its new size
  1508. * (which MAY be the requested size, or some other size if the
  1509. * requested one can't be achieved). The front end MAY also not
  1510. * call term_size() at all. But the front end MUST reply to this
  1511. * request by calling term_resize_request_completed(), after the
  1512. * responding resize event has taken place (if any).
  1513. *
  1514. * The calls to term_size and term_resize_request_completed may be
  1515. * synchronous callbacks from within the call to request_resize(). */
  1516. void (*request_resize)(TermWin *, int w, int h);
  1517. void (*set_title)(TermWin *, const char *title, int codepage);
  1518. void (*set_icon_title)(TermWin *, const char *icontitle, int codepage);
  1519. /* set_minimised and set_maximised are assumed to set two
  1520. * independent settings, rather than a single three-way
  1521. * {min,normal,max} switch. The idea is that when you un-minimise
  1522. * the window it remembers whether to go back to normal or
  1523. * maximised. */
  1524. void (*set_minimised)(TermWin *, bool minimised);
  1525. void (*set_maximised)(TermWin *, bool maximised);
  1526. void (*move)(TermWin *, int x, int y);
  1527. void (*set_zorder)(TermWin *, bool top);
  1528. /* Set the colour palette that the TermWin will use to display
  1529. * text. One call to this function sets 'ncolours' consecutive
  1530. * colours in the OSC 4 sequence, starting at 'start'. */
  1531. void (*palette_set)(TermWin *, unsigned start, unsigned ncolours,
  1532. const rgb *colours);
  1533. /* Query the front end for any OS-local overrides to the default
  1534. * colours stored in Conf. The front end should set any it cares
  1535. * about by calling term_palette_override.
  1536. *
  1537. * The Terminal object is passed in as a parameter, because this
  1538. * can be called as a callback from term_init(). So the TermWin
  1539. * itself won't yet have been told where to find its Terminal
  1540. * object, because that doesn't happen until term_init
  1541. * returns. */
  1542. void (*palette_get_overrides)(TermWin *, Terminal *);
  1543. /* Notify the front end that the terminal's buffer of unprocessed
  1544. * output has reduced. (Front ends will likely pass this straight
  1545. * on to backend_unthrottle.) */
  1546. void (*unthrottle)(TermWin *, size_t bufsize);
  1547. };
  1548. static inline bool win_setup_draw_ctx(TermWin *win)
  1549. { return win->vt->setup_draw_ctx(win); }
  1550. static inline void win_draw_text(
  1551. TermWin *win, int x, int y, wchar_t *text, int len,
  1552. unsigned long attrs, int line_attrs, truecolour tc)
  1553. { win->vt->draw_text(win, x, y, text, len, attrs, line_attrs, tc); }
  1554. static inline void win_draw_cursor(
  1555. TermWin *win, int x, int y, wchar_t *text, int len,
  1556. unsigned long attrs, int line_attrs, truecolour tc)
  1557. { win->vt->draw_cursor(win, x, y, text, len, attrs, line_attrs, tc); }
  1558. static inline void win_draw_trust_sigil(TermWin *win, int x, int y)
  1559. { win->vt->draw_trust_sigil(win, x, y); }
  1560. static inline int win_char_width(TermWin *win, int uc)
  1561. { return win->vt->char_width(win, uc); }
  1562. static inline void win_free_draw_ctx(TermWin *win)
  1563. { win->vt->free_draw_ctx(win); }
  1564. static inline void win_set_cursor_pos(TermWin *win, int x, int y)
  1565. { win->vt->set_cursor_pos(win, x, y); }
  1566. static inline void win_set_raw_mouse_mode(TermWin *win, bool enable)
  1567. { win->vt->set_raw_mouse_mode(win, enable); }
  1568. static inline void win_set_raw_mouse_mode_pointer(TermWin *win, bool enable)
  1569. { win->vt->set_raw_mouse_mode_pointer(win, enable); }
  1570. static inline void win_set_scrollbar(TermWin *win, int t, int s, int p)
  1571. { win->vt->set_scrollbar(win, t, s, p); }
  1572. static inline void win_bell(TermWin *win, int mode)
  1573. { win->vt->bell(win, mode); }
  1574. static inline void win_clip_write(
  1575. TermWin *win, int clipboard, wchar_t *text, int *attrs,
  1576. truecolour *colours, int len, bool deselect)
  1577. { win->vt->clip_write(win, clipboard, text, attrs, colours, len, deselect); }
  1578. static inline void win_clip_request_paste(TermWin *win, int clipboard)
  1579. { win->vt->clip_request_paste(win, clipboard); }
  1580. static inline void win_refresh(TermWin *win)
  1581. { win->vt->refresh(win); }
  1582. static inline void win_request_resize(TermWin *win, int w, int h)
  1583. { win->vt->request_resize(win, w, h); }
  1584. static inline void win_set_title(TermWin *win, const char *title, int codepage)
  1585. { win->vt->set_title(win, title, codepage); }
  1586. static inline void win_set_icon_title(TermWin *win, const char *icontitle,
  1587. int codepage)
  1588. { win->vt->set_icon_title(win, icontitle, codepage); }
  1589. static inline void win_set_minimised(TermWin *win, bool minimised)
  1590. { win->vt->set_minimised(win, minimised); }
  1591. static inline void win_set_maximised(TermWin *win, bool maximised)
  1592. { win->vt->set_maximised(win, maximised); }
  1593. static inline void win_move(TermWin *win, int x, int y)
  1594. { win->vt->move(win, x, y); }
  1595. static inline void win_set_zorder(TermWin *win, bool top)
  1596. { win->vt->set_zorder(win, top); }
  1597. static inline void win_palette_set(
  1598. TermWin *win, unsigned start, unsigned ncolours, const rgb *colours)
  1599. { win->vt->palette_set(win, start, ncolours, colours); }
  1600. static inline void win_palette_get_overrides(TermWin *win, Terminal *term)
  1601. { win->vt->palette_get_overrides(win, term); }
  1602. static inline void win_unthrottle(TermWin *win, size_t size)
  1603. { win->vt->unthrottle(win, size); }
  1604. /*
  1605. * Global functions not specific to a connection instance.
  1606. */
  1607. void nonfatal(const char *, ...) PRINTF_LIKE(1, 2);
  1608. NORETURN void modalfatalbox(const char *, ...) PRINTF_LIKE(1, 2);
  1609. NORETURN void cleanup_exit(int);
  1610. /*
  1611. * Exports from conf.c, and a big enum (via parametric macro) of
  1612. * configuration option keys.
  1613. */
  1614. /* The master list of option keywords lives in conf.h */
  1615. enum config_primary_key {
  1616. #define CONF_OPTION(keyword, ...) CONF_ ## keyword,
  1617. #include "conf.h"
  1618. #undef CONF_OPTION
  1619. N_CONFIG_OPTIONS
  1620. };
  1621. /* Types that appear in Conf keys and values. */
  1622. enum {
  1623. /*
  1624. * CONF_TYPE_NONE is included in this enum because sometimes you
  1625. * need a placeholder for 'no type found'. (In Rust you'd leave it
  1626. * out, and use Option<ConfType> for those situations.)
  1627. *
  1628. * In particular, it's used as the subkey type for options that
  1629. * don't have subkeys.
  1630. */
  1631. CONF_TYPE_NONE,
  1632. /* Booleans, accessed via conf_get_bool and conf_set_bool */
  1633. CONF_TYPE_BOOL,
  1634. /* Integers, accessed via conf_get_int and conf_set_int */
  1635. CONF_TYPE_INT,
  1636. /*
  1637. * NUL-terminated char strings, accessed via conf_get_str and
  1638. * conf_set_str.
  1639. *
  1640. * Where character encoding is relevant, these are generally
  1641. * expected to be in the host system's default character encoding.
  1642. *
  1643. * (Character encoding might not be relevant at all: for example,
  1644. * if the string is going to be used as a shell command on Unix,
  1645. * then the exec system call will want a char string anyway.)
  1646. */
  1647. CONF_TYPE_STR,
  1648. /* NUL-terminated char strings encoded in UTF-8, accessed via
  1649. * conf_get_utf8 and conf_set_utf8. */
  1650. CONF_TYPE_UTF8,
  1651. /*
  1652. * A type that can be _either_ a char string in system encoding
  1653. * (aka CONF_TYPE_STR), _or_ a char string in UTF-8 (aka
  1654. * CONF_TYPE_UTF8). You can set it to be one or the other via
  1655. * conf_set_str or conf_set_utf8. To read it, you must use
  1656. * conf_get_str_ambi(), which returns a char string and a boolean
  1657. * telling you whether it's UTF-8.
  1658. *
  1659. * These can't be used as _keys_ in Conf, only as values. (If you
  1660. * used them as keys, you'd have to answer the difficult question
  1661. * of whether a UTF-8 and a non-UTF-8 string should be considered
  1662. * equal.)
  1663. */
  1664. CONF_TYPE_STR_AMBI,
  1665. /* PuTTY's OS-specific 'Filename' data type, accessed via
  1666. * conf_get_filename and conf_set_filename */
  1667. CONF_TYPE_FILENAME,
  1668. /* PuTTY's GUI-specific 'FontSpec' data type, accessed via
  1669. * conf_get_fontspec and conf_set_fontspec */
  1670. CONF_TYPE_FONT,
  1671. };
  1672. struct ConfKeyInfo {
  1673. int subkey_type;
  1674. int value_type;
  1675. union {
  1676. bool bval;
  1677. int ival;
  1678. const char *sval;
  1679. } default_value;
  1680. bool save_custom : 1;
  1681. bool load_custom : 1;
  1682. bool not_saved : 1;
  1683. const char *save_keyword;
  1684. const ConfSaveEnumType *storage_enum;
  1685. };
  1686. struct ConfSaveEnumType {
  1687. const ConfSaveEnumValue *values;
  1688. size_t nvalues;
  1689. };
  1690. struct ConfSaveEnumValue {
  1691. int confval, storageval;
  1692. bool obsolete;
  1693. };
  1694. extern const ConfKeyInfo conf_key_info[];
  1695. bool conf_enum_map_to_storage(const ConfSaveEnumType *etype,
  1696. int confval, int *storageval_out);
  1697. bool conf_enum_map_from_storage(const ConfSaveEnumType *etype,
  1698. int storageval, int *confval_out);
  1699. /* Functions handling configuration structures. */
  1700. Conf *conf_new(void); /* create an empty configuration */
  1701. void conf_free(Conf *conf);
  1702. void conf_clear(Conf *conf); /* likely only useful for test programs */
  1703. Conf *conf_copy(Conf *oldconf);
  1704. void conf_copy_into(Conf *dest, Conf *src);
  1705. /* Mandatory accessor functions: enforce by assertion that keys exist. */
  1706. bool conf_get_bool(Conf *conf, int key);
  1707. int conf_get_int(Conf *conf, int key);
  1708. int conf_get_int_int(Conf *conf, int key, int subkey);
  1709. char *conf_get_str(Conf *conf, int key); /* result still owned by conf */
  1710. char *conf_get_utf8(Conf *conf, int key); /* result still owned by conf */
  1711. char *conf_get_str_ambi( /* result still owned by conf; 'utf8' may be NULL */
  1712. Conf *conf, int key, bool *utf8);
  1713. char *conf_get_str_str(Conf *conf, int key, const char *subkey);
  1714. Filename *conf_get_filename(Conf *conf, int key);
  1715. FontSpec *conf_get_fontspec(Conf *conf, int key); /* still owned by conf */
  1716. /* Optional accessor function: return NULL if key does not exist. */
  1717. char *conf_get_str_str_opt(Conf *conf, int key, const char *subkey);
  1718. /* Accessor function to step through a string-subkeyed list.
  1719. * Returns the next subkey after the provided one, or the first if NULL.
  1720. * Returns NULL if there are none left.
  1721. * Both the return value and *subkeyout are still owned by conf. */
  1722. char *conf_get_str_strs(Conf *conf, int key, char *subkeyin, char **subkeyout);
  1723. /* Return the nth string subkey in a list. Owned by conf. NULL if beyond end */
  1724. char *conf_get_str_nthstrkey(Conf *conf, int key, int n);
  1725. /* Functions to set entries in configuration. Always copy their inputs. */
  1726. void conf_set_bool(Conf *conf, int key, bool value);
  1727. void conf_set_int(Conf *conf, int key, int value);
  1728. void conf_set_int_int(Conf *conf, int key, int subkey, int value);
  1729. void conf_set_str(Conf *conf, int key, const char *value);
  1730. void conf_set_utf8(Conf *conf, int key, const char *value);
  1731. bool conf_try_set_str(Conf *conf, int key, const char *value);
  1732. bool conf_try_set_utf8(Conf *conf, int key, const char *value);
  1733. void conf_set_str_str(Conf *conf, int key,
  1734. const char *subkey, const char *val);
  1735. void conf_del_str_str(Conf *conf, int key, const char *subkey);
  1736. void conf_set_filename(Conf *conf, int key, const Filename *val);
  1737. void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
  1738. /* Serialisation functions for Duplicate Session */
  1739. void conf_serialise(BinarySink *bs, Conf *conf);
  1740. bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
  1741. /*
  1742. * Functions to copy, free, serialise and deserialise FontSpecs.
  1743. * Provided per-platform, to go with the platform's idea of a
  1744. * FontSpec's contents.
  1745. *
  1746. * The full fontspec_new is declared in the platform header, because
  1747. * each platform may need it to have a different prototype, due to
  1748. * constructing fonts in different ways. But fontspec_new_default()
  1749. * will at least produce _some_ kind of a FontSpec, for use in
  1750. * situations where one needs to exist (e.g. to put in a Conf) and be
  1751. * freeable but won't actually be used for anything important.
  1752. */
  1753. FontSpec *fontspec_new_default(void);
  1754. FontSpec *fontspec_copy(const FontSpec *f);
  1755. void fontspec_free(FontSpec *f);
  1756. void fontspec_serialise(BinarySink *bs, FontSpec *f);
  1757. FontSpec *fontspec_deserialise(BinarySource *src);
  1758. /*
  1759. * Exports from each platform's noise.c.
  1760. */
  1761. typedef enum NoiseSourceId {
  1762. NOISE_SOURCE_TIME,
  1763. NOISE_SOURCE_IOID,
  1764. NOISE_SOURCE_IOLEN,
  1765. NOISE_SOURCE_KEY,
  1766. NOISE_SOURCE_MOUSEBUTTON,
  1767. NOISE_SOURCE_MOUSEPOS,
  1768. NOISE_SOURCE_MEMINFO,
  1769. NOISE_SOURCE_STAT,
  1770. NOISE_SOURCE_RUSAGE,
  1771. NOISE_SOURCE_FGWINDOW,
  1772. NOISE_SOURCE_CAPTURE,
  1773. NOISE_SOURCE_CLIPBOARD,
  1774. NOISE_SOURCE_QUEUE,
  1775. NOISE_SOURCE_CURSORPOS,
  1776. NOISE_SOURCE_THREADTIME,
  1777. NOISE_SOURCE_PROCTIME,
  1778. NOISE_SOURCE_PERFCOUNT,
  1779. NOISE_MAX_SOURCES
  1780. } NoiseSourceId;
  1781. void noise_get_heavy(void (*func) (void *, int));
  1782. void noise_get_light(void (*func) (void *, int));
  1783. void noise_regular(void);
  1784. void noise_ultralight(NoiseSourceId id, unsigned long data);
  1785. /*
  1786. * Exports from sshrand.c.
  1787. */
  1788. void random_save_seed(void);
  1789. void random_destroy_seed(void);
  1790. /*
  1791. * Exports from settings.c.
  1792. *
  1793. * load_settings() and do_defaults() return false if the provided
  1794. * session name didn't actually exist. But they still fill in the
  1795. * provided Conf with _something_.
  1796. */
  1797. const struct BackendVtable *backend_vt_from_name(const char *name);
  1798. const struct BackendVtable *backend_vt_from_proto(int proto);
  1799. char *get_remote_username(Conf *conf); /* dynamically allocated */
  1800. char *save_settings(const char *section, Conf *conf);
  1801. void save_open_settings(settings_w *sesskey, Conf *conf);
  1802. bool load_settings(const char *section, Conf *conf);
  1803. void load_open_settings(settings_r *sesskey, Conf *conf);
  1804. void get_sesslist(struct sesslist *, bool allocate);
  1805. bool do_defaults(const char *, Conf *);
  1806. void registry_cleanup(void);
  1807. void settings_set_default_protocol(int);
  1808. void settings_set_default_port(int);
  1809. /*
  1810. * Functions used by settings.c to provide platform-specific
  1811. * default settings.
  1812. *
  1813. * (The integer one is expected to return `def' if it has no clear
  1814. * opinion of its own. This is because there's no integer value
  1815. * which I can reliably set aside to indicate `nil'. The string
  1816. * function is perfectly all right returning NULL, of course. The
  1817. * Filename and FontSpec functions are _not allowed_ to fail to
  1818. * return, since these defaults _must_ be per-platform.)
  1819. *
  1820. * The 'Filename *' returned by platform_default_filename, and the
  1821. * 'FontSpec *' returned by platform_default_fontspec, have ownership
  1822. * transferred to the caller, and must be freed.
  1823. */
  1824. char *platform_default_s(const char *name);
  1825. bool platform_default_b(const char *name, bool def);
  1826. int platform_default_i(const char *name, int def);
  1827. Filename *platform_default_filename(const char *name);
  1828. FontSpec *platform_default_fontspec(const char *name);
  1829. /*
  1830. * Exports from terminal.c.
  1831. */
  1832. Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
  1833. void term_free(Terminal *);
  1834. void term_size(Terminal *, int, int, int);
  1835. void term_resize_request_completed(Terminal *);
  1836. void term_paint(Terminal *, int, int, int, int, bool);
  1837. void term_scroll(Terminal *, int, int);
  1838. void term_scroll_to_selection(Terminal *, int);
  1839. void term_pwron(Terminal *, bool);
  1840. void term_clrsb(Terminal *);
  1841. void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
  1842. int, int, bool, bool, bool);
  1843. void term_cancel_selection_drag(Terminal *);
  1844. void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
  1845. unsigned int);
  1846. void term_lost_clipboard_ownership(Terminal *, int clipboard);
  1847. void term_update(Terminal *);
  1848. void term_invalidate(Terminal *);
  1849. void term_blink(Terminal *, bool set_cursor);
  1850. void term_do_paste(Terminal *, const wchar_t *, size_t);
  1851. void term_nopaste(Terminal *);
  1852. void term_copyall(Terminal *, const int *, int);
  1853. void term_pre_reconfig(Terminal *, Conf *);
  1854. void term_reconfig(Terminal *, Conf *);
  1855. void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
  1856. void term_request_paste(Terminal *, int clipboard);
  1857. void term_seen_key_event(Terminal *);
  1858. size_t term_data(Terminal *, const void *data, size_t len);
  1859. void term_provide_backend(Terminal *term, Backend *backend);
  1860. void term_provide_logctx(Terminal *term, LogContext *logctx);
  1861. void term_set_focus(Terminal *term, bool has_focus);
  1862. char *term_get_ttymode(Terminal *term, const char *mode);
  1863. SeatPromptResult term_get_userpass_input(Terminal *term, prompts_t *p);
  1864. void term_set_trust_status(Terminal *term, bool trusted);
  1865. void term_keyinput(Terminal *, int codepage, const void *buf, int len);
  1866. void term_keyinputw(Terminal *, const wchar_t *widebuf, int len);
  1867. void term_get_cursor_position(Terminal *term, int *x, int *y);
  1868. void term_setup_window_titles(Terminal *term, const char *title_hostname);
  1869. void term_notify_minimised(Terminal *term, bool minimised);
  1870. void term_notify_palette_changed(Terminal *term);
  1871. void term_notify_window_pos(Terminal *term, int x, int y);
  1872. void term_notify_window_size_pixels(Terminal *term, int x, int y);
  1873. void term_palette_override(Terminal *term, unsigned osc4_index, rgb rgb);
  1874. typedef enum SmallKeypadKey {
  1875. SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN,
  1876. } SmallKeypadKey;
  1877. int format_arrow_key(char *buf, Terminal *term, int xkey,
  1878. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  1879. int format_function_key(char *buf, Terminal *term, int key_number,
  1880. bool shift, bool ctrl, bool alt, bool *consumed_alt);
  1881. int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key,
  1882. bool shift, bool ctrl, bool alt,
  1883. bool *consumed_alt);
  1884. int format_numeric_keypad_key(char *buf, Terminal *term, char key,
  1885. bool shift, bool ctrl);
  1886. /*
  1887. * Exports from logging.c.
  1888. */
  1889. struct LogPolicyVtable {
  1890. /*
  1891. * Pass Event Log entries on from LogContext to the front end,
  1892. * which might write them to standard error or save them for a GUI
  1893. * list box or other things.
  1894. */
  1895. void (*eventlog)(LogPolicy *lp, const char *event);
  1896. /*
  1897. * Ask what to do about the specified output log file already
  1898. * existing. Can return four values:
  1899. *
  1900. * - 2 means overwrite the log file
  1901. * - 1 means append to the log file
  1902. * - 0 means cancel logging for this session
  1903. * - -1 means please wait, and callback() will be called with one
  1904. * of those options.
  1905. */
  1906. int (*askappend)(LogPolicy *lp, Filename *filename,
  1907. void (*callback)(void *ctx, int result), void *ctx);
  1908. /*
  1909. * Emergency logging when the log file itself can't be opened,
  1910. * which typically means we want to shout about it more loudly
  1911. * than a mere Event Log entry.
  1912. *
  1913. * One reasonable option is to send it to the same place that
  1914. * stderr output from the main session goes (so, either a console
  1915. * tool's actual stderr, or a terminal window). In many cases this
  1916. * is unlikely to cause this error message to turn up
  1917. * embarrassingly in a log file of real server output, because the
  1918. * whole point is that we haven't managed to open any such log
  1919. * file :-)
  1920. */
  1921. void (*logging_error)(LogPolicy *lp, const char *event);
  1922. /*
  1923. * Ask whether extra verbose log messages are required.
  1924. */
  1925. bool (*verbose)(LogPolicy *lp);
  1926. };
  1927. struct LogPolicy {
  1928. const LogPolicyVtable *vt;
  1929. };
  1930. static inline void lp_eventlog(LogPolicy *lp, const char *event)
  1931. { lp->vt->eventlog(lp, event); }
  1932. static inline int lp_askappend(
  1933. LogPolicy *lp, Filename *filename,
  1934. void (*callback)(void *ctx, int result), void *ctx)
  1935. { return lp->vt->askappend(lp, filename, callback, ctx); }
  1936. static inline void lp_logging_error(LogPolicy *lp, const char *event)
  1937. { lp->vt->logging_error(lp, event); }
  1938. static inline bool lp_verbose(LogPolicy *lp)
  1939. { return lp->vt->verbose(lp); }
  1940. /* Defined in clicons.c, used in several console command-line tools */
  1941. extern LogPolicy console_cli_logpolicy[];
  1942. int console_askappend(LogPolicy *lp, Filename *filename,
  1943. void (*callback)(void *ctx, int result), void *ctx);
  1944. void console_logging_error(LogPolicy *lp, const char *string);
  1945. void console_eventlog(LogPolicy *lp, const char *string);
  1946. bool null_lp_verbose_yes(LogPolicy *lp);
  1947. bool null_lp_verbose_no(LogPolicy *lp);
  1948. bool cmdline_lp_verbose(LogPolicy *lp);
  1949. LogContext *log_init(LogPolicy *lp, Conf *conf);
  1950. void log_free(LogContext *logctx);
  1951. void log_reconfig(LogContext *logctx, Conf *conf);
  1952. void logfopen(LogContext *logctx);
  1953. void logfclose(LogContext *logctx);
  1954. void logtraffic(LogContext *logctx, unsigned char c, int logmode);
  1955. void logflush(LogContext *logctx);
  1956. LogPolicy *log_get_policy(LogContext *logctx);
  1957. void logevent(LogContext *logctx, const char *event);
  1958. void logeventf(LogContext *logctx, const char *fmt, ...) PRINTF_LIKE(2, 3);
  1959. void logeventvf(LogContext *logctx, const char *fmt, va_list ap);
  1960. /*
  1961. * Pass a dynamically allocated string to logevent and immediately
  1962. * free it. Intended for use by wrapper macros which pass the return
  1963. * value of dupprintf straight to this.
  1964. */
  1965. void logevent_and_free(LogContext *logctx, char *event);
  1966. enum { PKT_INCOMING, PKT_OUTGOING };
  1967. enum { PKTLOG_EMIT, PKTLOG_BLANK, PKTLOG_OMIT };
  1968. struct logblank_t {
  1969. int offset;
  1970. int len;
  1971. int type;
  1972. };
  1973. void log_packet(LogContext *logctx, int direction, int type,
  1974. const char *texttype, const void *data, size_t len,
  1975. int n_blanks, const struct logblank_t *blanks,
  1976. const unsigned long *sequence,
  1977. unsigned downstream_id, const char *additional_log_text);
  1978. /*
  1979. * Exports from testback.c
  1980. */
  1981. extern const struct BackendVtable null_backend;
  1982. extern const struct BackendVtable loop_backend;
  1983. /*
  1984. * Exports from raw.c.
  1985. */
  1986. extern const struct BackendVtable raw_backend;
  1987. /*
  1988. * Exports from rlogin.c.
  1989. */
  1990. extern const struct BackendVtable rlogin_backend;
  1991. /*
  1992. * Exports from telnet.c.
  1993. */
  1994. extern const struct BackendVtable telnet_backend;
  1995. /*
  1996. * Exports from ssh/ssh.c.
  1997. */
  1998. extern const struct BackendVtable ssh_backend;
  1999. extern const struct BackendVtable sshconn_backend;
  2000. /*
  2001. * Exports from supdup.c.
  2002. */
  2003. extern const struct BackendVtable supdup_backend;
  2004. /*
  2005. * Exports from ldisc.c.
  2006. */
  2007. Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
  2008. void ldisc_configure(Ldisc *, Conf *);
  2009. void ldisc_free(Ldisc *);
  2010. void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
  2011. void ldisc_echoedit_update(Ldisc *);
  2012. void ldisc_provide_userpass_le(Ldisc *, TermLineEditor *);
  2013. void ldisc_check_sendok(Ldisc *);
  2014. /*
  2015. * Exports from sshrand.c.
  2016. */
  2017. void random_add_noise(NoiseSourceId source, const void *noise, int length);
  2018. void random_read(void *buf, size_t size);
  2019. void random_get_savedata(void **data, int *len);
  2020. extern int random_active;
  2021. /* The random number subsystem is activated if at least one other entity
  2022. * within the program expresses an interest in it. So each SSH session
  2023. * calls random_ref on startup and random_unref on shutdown. */
  2024. void random_ref(void);
  2025. void random_unref(void);
  2026. /* random_clear is equivalent to calling random_unref as many times as
  2027. * necessary to shut down the global PRNG instance completely. It's
  2028. * not needed in normal applications, but the command-line PuTTYgen
  2029. * test finds it useful to clean up after each invocation of the
  2030. * logical main() no matter whether it needed random numbers or
  2031. * not. */
  2032. void random_clear(void);
  2033. /* random_setup_custom sets up the process-global random number
  2034. * generator specially, with a hash function of your choice. */
  2035. void random_setup_custom(const ssh_hashalg *hash);
  2036. /* random_setup_special() is a macro wrapper on that, which makes an
  2037. * extra-big one based on the largest hash function we have. It's
  2038. * defined this way to avoid what would otherwise be an unnecessary
  2039. * module dependency from sshrand.c to a hash function implementation. */
  2040. #define random_setup_special() random_setup_custom(&ssh_shake256_114bytes)
  2041. /* Manually drop a random seed into the random number generator, e.g.
  2042. * just before generating a key. */
  2043. void random_reseed(ptrlen seed);
  2044. /* Limit on how much entropy is worth putting into the generator (bits). */
  2045. size_t random_seed_bits(void);
  2046. /*
  2047. * Exports from pinger.c.
  2048. */
  2049. typedef struct Pinger Pinger;
  2050. Pinger *pinger_new(Conf *conf, Backend *backend);
  2051. void pinger_reconfig(Pinger *, Conf *oldconf, Conf *newconf);
  2052. void pinger_free(Pinger *);
  2053. /*
  2054. * Exports from modules in utils.
  2055. */
  2056. #include "misc.h"
  2057. bool conf_launchable(Conf *conf);
  2058. char const *conf_dest(Conf *conf);
  2059. /*
  2060. * Exports from sessprep.c.
  2061. */
  2062. void prepare_session(Conf *conf);
  2063. /*
  2064. * Exports from version.c and cmake_commit.c.
  2065. */
  2066. extern const char ver[];
  2067. extern const char commitid[];
  2068. /*
  2069. * Exports from unicode.c in platform subdirs.
  2070. */
  2071. /* void init_ucs(void); -- this is now in platform-specific headers */
  2072. bool is_dbcs_leadbyte(int codepage, char byte);
  2073. /* For put_mb_to_wc / put_wc_to_mb, see marshal.h */
  2074. wchar_t xlat_uskbd2cyrllic(int ch);
  2075. int check_compose(int first, int second);
  2076. int decode_codepage(const char *cp_name);
  2077. const char *cp_enumerate (int index);
  2078. const char *cp_name(int codepage);
  2079. void get_unitab(int codepage, wchar_t *unitab, int ftype);
  2080. /*
  2081. * Exports from wcwidth.c
  2082. */
  2083. int mk_wcwidth(unsigned int ucs);
  2084. int mk_wcswidth(const unsigned int *pwcs, size_t n);
  2085. int mk_wcwidth_cjk(unsigned int ucs);
  2086. int mk_wcswidth_cjk(const unsigned int *pwcs, size_t n);
  2087. /*
  2088. * Exports from agent-client.c in platform subdirs.
  2089. *
  2090. * agent_query returns NULL for here's-a-response, and non-NULL for
  2091. * query-in- progress. In the latter case there will be a call to
  2092. * `callback' at some future point, passing callback_ctx as the first
  2093. * parameter and the actual reply data as the second and third.
  2094. *
  2095. * The response may be a NULL pointer (in either of the synchronous
  2096. * or asynchronous cases), which indicates failure to receive a
  2097. * response.
  2098. *
  2099. * When the return from agent_query is not NULL, it identifies the
  2100. * in-progress query in case it needs to be cancelled. If
  2101. * agent_cancel_query is called, then the pending query is destroyed
  2102. * and the callback will not be called. (E.g. if you're going to throw
  2103. * away the thing you were using as callback_ctx.)
  2104. *
  2105. * Passing a null pointer as callback forces agent_query to behave
  2106. * synchronously, i.e. it will block if necessary, and guarantee to
  2107. * return NULL. The wrapper function agent_query_synchronous()
  2108. * (defined in its own module aqsync.c) makes this easier.
  2109. */
  2110. typedef struct agent_pending_query agent_pending_query;
  2111. agent_pending_query *agent_query(
  2112. strbuf *in, void **out, int *outlen,
  2113. void (*callback)(void *, void *, int), void *callback_ctx);
  2114. void agent_cancel_query(agent_pending_query *);
  2115. void agent_query_synchronous(strbuf *in, void **out, int *outlen);
  2116. bool agent_exists(void);
  2117. /* For stream-oriented agent connections, if available. */
  2118. Socket *agent_connect(Plug *plug);
  2119. /*
  2120. * Exports from wildcard.c
  2121. */
  2122. const char *wc_error(int value);
  2123. int wc_match_pl(const char *wildcard, ptrlen target);
  2124. int wc_match(const char *wildcard, const char *target);
  2125. bool wc_unescape(char *output, const char *wildcard);
  2126. /*
  2127. * Exports from frontend (dialog.c etc)
  2128. */
  2129. void pgp_fingerprints(void);
  2130. /*
  2131. * have_ssh_host_key() just returns true if a key of that type is
  2132. * already cached and false otherwise.
  2133. */
  2134. bool have_ssh_host_key(const char *host, int port, const char *keytype);
  2135. /*
  2136. * Exports from console frontends (console.c in platform subdirs)
  2137. * that aren't equivalents to things in windlg.c et al.
  2138. */
  2139. extern bool console_batch_mode, console_antispoof_prompt;
  2140. extern bool console_set_batch_mode(bool);
  2141. extern bool console_set_stdio_prompts(bool);
  2142. SeatPromptResult console_get_userpass_input(prompts_t *p);
  2143. bool is_interactive(void);
  2144. void console_print_error_msg(const char *prefix, const char *msg);
  2145. void console_print_error_msg_fmt_v(
  2146. const char *prefix, const char *fmt, va_list ap);
  2147. void console_print_error_msg_fmt(const char *prefix, const char *fmt, ...)
  2148. PRINTF_LIKE(2, 3);
  2149. /*
  2150. * Exports from either console frontends or terminal.c.
  2151. */
  2152. extern bool set_legacy_charset_handling(bool);
  2153. /*
  2154. * Exports from printing.c in platform subdirs.
  2155. */
  2156. typedef struct printer_enum_tag printer_enum;
  2157. typedef struct printer_job_tag printer_job;
  2158. printer_enum *printer_start_enum(int *nprinters);
  2159. char *printer_get_name(printer_enum *, int);
  2160. void printer_finish_enum(printer_enum *);
  2161. printer_job *printer_start_job(char *printer);
  2162. void printer_job_data(printer_job *, const void *, size_t);
  2163. void printer_finish_job(printer_job *);
  2164. /*
  2165. * Exports from cmdline.c (and also cmdline_error(), which is
  2166. * defined differently in various places and required _by_
  2167. * cmdline.c).
  2168. */
  2169. struct cmdline_get_passwd_input_state { bool tried; };
  2170. #define CMDLINE_GET_PASSWD_INPUT_STATE_INIT { .tried = false }
  2171. extern const cmdline_get_passwd_input_state cmdline_get_passwd_input_state_new;
  2172. int cmdline_process_param(CmdlineArg *, CmdlineArg *, int, Conf *);
  2173. void cmdline_run_saved(Conf *);
  2174. void cmdline_cleanup(void);
  2175. SeatPromptResult cmdline_get_passwd_input(
  2176. prompts_t *p, cmdline_get_passwd_input_state *state, bool restartable);
  2177. bool cmdline_host_ok(Conf *);
  2178. bool cmdline_verbose(void);
  2179. bool cmdline_loaded_session(void);
  2180. /*
  2181. * Abstraction provided by each platform to represent a command-line
  2182. * argument. May not be as simple as a default-encoded string: on
  2183. * Windows, command lines can be Unicode representing characters not
  2184. * in the system codepage, so you might need to retrieve the argument
  2185. * in a richer form.
  2186. */
  2187. struct CmdlineArgList {
  2188. /* args[0], args[1], ... represent the original arguments in the
  2189. * command line. Then there's a null pointer. Further arguments
  2190. * can be invented to add to the array after that, in which case
  2191. * they'll be freed with the rest of the CmdlineArgList, but
  2192. * aren't logically part of the original command line. */
  2193. CmdlineArg **args;
  2194. size_t nargs, argssize;
  2195. };
  2196. struct CmdlineArg {
  2197. CmdlineArgList *list;
  2198. };
  2199. const char *cmdline_arg_to_utf8(CmdlineArg *arg); /* may fail */
  2200. const char *cmdline_arg_to_str(CmdlineArg *arg); /* must not fail */
  2201. Filename *cmdline_arg_to_filename(CmdlineArg *arg); /* caller must free */
  2202. void cmdline_arg_wipe(CmdlineArg *arg);
  2203. CmdlineArg *cmdline_arg_from_str(CmdlineArgList *list, const char *string);
  2204. /* Platforms provide their own constructors for CmdlineArgList */
  2205. void cmdline_arg_list_free(CmdlineArgList *list);
  2206. /*
  2207. * Here we have a flags word provided by each tool, which describes
  2208. * the capabilities of that tool that cmdline.c needs to know about.
  2209. * It will refuse certain command-line options if a particular tool
  2210. * inherently can't do anything sensible. For example, the file
  2211. * transfer tools (psftp, pscp) can't do a great deal with protocol
  2212. * selections (ever tried running scp over telnet?) or with port
  2213. * forwarding (even if it wasn't a hideously bad idea, they don't have
  2214. * the select/poll infrastructure to make them work).
  2215. */
  2216. extern const unsigned cmdline_tooltype;
  2217. /* Bit flags for the above */
  2218. #define TOOLTYPE_LIST(X) \
  2219. X(TOOLTYPE_FILETRANSFER) \
  2220. X(TOOLTYPE_NONNETWORK) \
  2221. X(TOOLTYPE_HOST_ARG) \
  2222. X(TOOLTYPE_HOST_ARG_CAN_BE_SESSION) \
  2223. X(TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX) \
  2224. X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \
  2225. X(TOOLTYPE_PORT_ARG) \
  2226. X(TOOLTYPE_NO_VERBOSE_OPTION) \
  2227. X(TOOLTYPE_GUI) \
  2228. /* end of list */
  2229. #define BITFLAG_INDEX(val) val ## _bitflag_index,
  2230. enum { TOOLTYPE_LIST(BITFLAG_INDEX) };
  2231. #define BITFLAG_DEF(val) val = 1U << (val ## _bitflag_index),
  2232. enum { TOOLTYPE_LIST(BITFLAG_DEF) };
  2233. void cmdline_error(const char *, ...) PRINTF_LIKE(1, 2);
  2234. /*
  2235. * Exports from config.c.
  2236. */
  2237. struct controlbox;
  2238. void conf_radiobutton_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2239. void *data, int event);
  2240. #define CHECKBOX_INVERT (1<<30)
  2241. void conf_checkbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2242. void *data, int event);
  2243. void conf_editbox_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2244. void *data, int event);
  2245. void conf_filesel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2246. void *data, int event);
  2247. void conf_fontsel_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2248. void *data, int event);
  2249. struct conf_editbox_handler_type {
  2250. /* Structure passed as context2 to conf_editbox_handler */
  2251. enum { EDIT_STR, EDIT_INT, EDIT_FIXEDPOINT } type;
  2252. union {
  2253. /*
  2254. * EDIT_STR means the edit box is connected to a string
  2255. * field in Conf. No further parameters needed.
  2256. */
  2257. /*
  2258. * EDIT_INT means the edit box is connected to an int field in
  2259. * Conf, and the input string is interpreted as decimal. No
  2260. * further parameters needed. (But we could add one here later
  2261. * if for some reason we wanted int fields in hex.)
  2262. */
  2263. /*
  2264. * EDIT_FIXEDPOINT means the edit box is connected to an int
  2265. * field in Conf, but the input string is interpreted as
  2266. * _floating point_, and converted to/from the output int by
  2267. * means of a fixed denominator. That is,
  2268. *
  2269. * (floating value in edit box) * denominator = value in Conf
  2270. */
  2271. struct {
  2272. double denominator;
  2273. };
  2274. };
  2275. };
  2276. extern const struct conf_editbox_handler_type conf_editbox_str;
  2277. extern const struct conf_editbox_handler_type conf_editbox_int;
  2278. #define ED_STR CP(&conf_editbox_str)
  2279. #define ED_INT CP(&conf_editbox_int)
  2280. void setup_config_box(struct controlbox *b, bool midsession,
  2281. int protocol, int protcfginfo);
  2282. void setup_ca_config_box(struct controlbox *b);
  2283. /* Platforms provide this to be called from config.c */
  2284. void show_ca_config_box(dlgparam *dlg);
  2285. extern const bool has_ca_config_box; /* false if, e.g., we're PuTTYtel */
  2286. /* Visible outside config.c so that platforms can use it to recognise
  2287. * the proxy type control */
  2288. void proxy_type_handler(dlgcontrol *ctrl, dlgparam *dlg,
  2289. void *data, int event);
  2290. /* And then they'll set this flag in its generic.context.i */
  2291. #define PROXY_UI_FLAG_LOCAL 1 /* has a local proxy */
  2292. /*
  2293. * Exports from bidi.c.
  2294. */
  2295. #define BIDI_CHAR_INDEX_NONE ((unsigned short)-1)
  2296. typedef struct bidi_char {
  2297. unsigned int origwc, wc;
  2298. unsigned short index, nchars;
  2299. } bidi_char;
  2300. BidiContext *bidi_new_context(void);
  2301. void bidi_free_context(BidiContext *ctx);
  2302. void do_bidi(BidiContext *ctx, bidi_char *line, size_t count);
  2303. int do_shape(bidi_char *line, bidi_char *to, int count);
  2304. bool is_rtl(int c);
  2305. /*
  2306. * X11 auth mechanisms we know about.
  2307. */
  2308. enum {
  2309. X11_NO_AUTH,
  2310. X11_MIT, /* MIT-MAGIC-COOKIE-1 */
  2311. X11_XDM, /* XDM-AUTHORIZATION-1 */
  2312. X11_NAUTHS
  2313. };
  2314. extern const char *const x11_authnames[X11_NAUTHS];
  2315. /*
  2316. * An enum for the copy-paste UI action configuration.
  2317. */
  2318. enum {
  2319. CLIPUI_NONE, /* UI action has no copy/paste effect */
  2320. CLIPUI_IMPLICIT, /* use the default clipboard implicit in mouse actions */
  2321. CLIPUI_EXPLICIT, /* use the default clipboard for explicit Copy/Paste */
  2322. CLIPUI_CUSTOM, /* use a named clipboard (on systems that support it) */
  2323. };
  2324. /*
  2325. * Miscellaneous exports from the platform-specific code.
  2326. *
  2327. * filename_serialise and filename_deserialise have the same semantics
  2328. * as fontspec_serialise and fontspec_deserialise above.
  2329. */
  2330. Filename *filename_from_str(const char *string);
  2331. const char *filename_to_str(const Filename *fn);
  2332. bool filename_equal(const Filename *f1, const Filename *f2);
  2333. bool filename_is_null(const Filename *fn);
  2334. Filename *filename_copy(const Filename *fn);
  2335. void filename_free(Filename *fn);
  2336. void filename_serialise(BinarySink *bs, const Filename *f);
  2337. Filename *filename_deserialise(BinarySource *src);
  2338. char *get_username(void); /* return value needs freeing */
  2339. char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
  2340. char filename_char_sanitise(char c); /* rewrite special pathname chars */
  2341. bool open_for_write_would_lose_data(const Filename *fn);
  2342. /*
  2343. * Exports and imports from timing.c.
  2344. *
  2345. * schedule_timer() asks the front end to schedule a callback to a
  2346. * timer function in a given number of ticks. The returned value is
  2347. * the time (in ticks since an arbitrary offset) at which the
  2348. * callback can be expected. This value will also be passed as the
  2349. * `now' parameter to the callback function. Hence, you can (for
  2350. * example) schedule an event at a particular time by calling
  2351. * schedule_timer() and storing the return value in your context
  2352. * structure as the time when that event is due. The first time a
  2353. * callback function gives you that value or more as `now', you do
  2354. * the thing.
  2355. *
  2356. * expire_timer_context() drops all current timers associated with
  2357. * a given value of ctx (for when you're about to free ctx).
  2358. *
  2359. * run_timers() is called from the front end when it has reason to
  2360. * think some timers have reached their moment, or when it simply
  2361. * needs to know how long to wait next. We pass it the time we
  2362. * think it is. It returns true and places the time when the next
  2363. * timer needs to go off in `next', or alternatively it returns
  2364. * false if there are no timers at all pending.
  2365. *
  2366. * timer_change_notify() must be supplied by the front end; it
  2367. * notifies the front end that a new timer has been added to the
  2368. * list which is sooner than any existing ones. It provides the
  2369. * time when that timer needs to go off.
  2370. *
  2371. * *** FRONT END IMPLEMENTORS NOTE:
  2372. *
  2373. * There's an important subtlety in the front-end implementation of
  2374. * the timer interface. When a front end is given a `next' value,
  2375. * either returned from run_timers() or via timer_change_notify(),
  2376. * it should ensure that it really passes _that value_ as the `now'
  2377. * parameter to its next run_timers call. It should _not_ simply
  2378. * call GETTICKCOUNT() to get the `now' parameter when invoking
  2379. * run_timers().
  2380. *
  2381. * The reason for this is that an OS's system clock might not agree
  2382. * exactly with the timing mechanisms it supplies to wait for a
  2383. * given interval. I'll illustrate this by the simple example of
  2384. * Unix Plink, which uses timeouts to poll() in a way which for
  2385. * these purposes can simply be considered to be a wait() function.
  2386. * Suppose, for the sake of argument, that this wait() function
  2387. * tends to return early by 1%. Then a possible sequence of actions
  2388. * is:
  2389. *
  2390. * - run_timers() tells the front end that the next timer firing
  2391. * is 10000ms from now.
  2392. * - Front end calls wait(10000ms), but according to
  2393. * GETTICKCOUNT() it has only waited for 9900ms.
  2394. * - Front end calls run_timers() again, passing time T-100ms as
  2395. * `now'.
  2396. * - run_timers() does nothing, and says the next timer firing is
  2397. * still 100ms from now.
  2398. * - Front end calls wait(100ms), which only waits for 99ms.
  2399. * - Front end calls run_timers() yet again, passing time T-1ms.
  2400. * - run_timers() says there's still 1ms to wait.
  2401. * - Front end calls wait(1ms).
  2402. *
  2403. * If you're _lucky_ at this point, wait(1ms) will actually wait
  2404. * for 1ms and you'll only have woken the program up three times.
  2405. * If you're unlucky, wait(1ms) might do nothing at all due to
  2406. * being below some minimum threshold, and you might find your
  2407. * program spends the whole of the last millisecond tight-looping
  2408. * between wait() and run_timers().
  2409. *
  2410. * Instead, what you should do is to _save_ the precise `next'
  2411. * value provided by run_timers() or via timer_change_notify(), and
  2412. * use that precise value as the input to the next run_timers()
  2413. * call. So:
  2414. *
  2415. * - run_timers() tells the front end that the next timer firing
  2416. * is at time T, 10000ms from now.
  2417. * - Front end calls wait(10000ms).
  2418. * - Front end then immediately calls run_timers() and passes it
  2419. * time T, without stopping to check GETTICKCOUNT() at all.
  2420. *
  2421. * This guarantees that the program wakes up only as many times as
  2422. * there are actual timer actions to be taken, and that the timing
  2423. * mechanism will never send it into a tight loop.
  2424. *
  2425. * (It does also mean that the timer action in the above example
  2426. * will occur 100ms early, but this is not generally critical. And
  2427. * the hypothetical 1% error in wait() will be partially corrected
  2428. * for anyway when, _after_ run_timers() returns, you call
  2429. * GETTICKCOUNT() and compare the result with the returned `next'
  2430. * value to find out how long you have to make your next wait().)
  2431. */
  2432. typedef void (*timer_fn_t)(void *ctx, unsigned long now);
  2433. unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
  2434. void expire_timer_context(void *ctx);
  2435. bool run_timers(unsigned long now, unsigned long *next);
  2436. void timer_change_notify(unsigned long next);
  2437. unsigned long timing_last_clock(void);
  2438. /*
  2439. * Exports from callback.c.
  2440. *
  2441. * This provides a method of queuing function calls to be run at the
  2442. * earliest convenience from the top-level event loop. Use it if
  2443. * you're deep in a nested chain of calls and want to trigger an
  2444. * action which will probably lead to your function being re-entered
  2445. * recursively if you just call the initiating function the normal
  2446. * way.
  2447. *
  2448. * Most front ends run the queued callbacks by simply calling
  2449. * run_toplevel_callbacks() after handling each event in their
  2450. * top-level event loop. However, if a front end doesn't have control
  2451. * over its own event loop (e.g. because it's using GTK) then it can
  2452. * instead request notifications when a callback is available, so that
  2453. * it knows to ask its delegate event loop to do the same thing. Also,
  2454. * if a front end needs to know whether a callback is pending without
  2455. * actually running it (e.g. so as to put a zero timeout on a poll()
  2456. * call) then it can call toplevel_callback_pending(), which will
  2457. * return true if at least one callback is in the queue.
  2458. *
  2459. * run_toplevel_callbacks() returns true if it ran any actual code.
  2460. * This can be used as a means of speculatively terminating a poll
  2461. * loop, as in PSFTP, for example - if a callback has run then perhaps
  2462. * it might have done whatever the loop's caller was waiting for.
  2463. */
  2464. void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
  2465. bool run_toplevel_callbacks(void);
  2466. bool toplevel_callback_pending(void);
  2467. void delete_callbacks_for_context(void *ctx);
  2468. /*
  2469. * Another facility in callback.c deals with 'idempotent' callbacks,
  2470. * defined as those which never need to be scheduled again if they are
  2471. * already scheduled and have not yet run. (An example would be one
  2472. * which, when called, empties a queue of data completely: when data
  2473. * is added to the queue, you must ensure a run of the queue-consuming
  2474. * function has been scheduled, but if one is already pending, you
  2475. * don't need to schedule a second one.)
  2476. */
  2477. struct IdempotentCallback {
  2478. toplevel_callback_fn_t fn;
  2479. void *ctx;
  2480. bool queued;
  2481. };
  2482. void queue_idempotent_callback(struct IdempotentCallback *ic);
  2483. typedef void (*toplevel_callback_notify_fn_t)(void *ctx);
  2484. void request_callback_notifications(toplevel_callback_notify_fn_t notify,
  2485. void *ctx);
  2486. /*
  2487. * Facility provided by the platform to spawn a parallel subprocess
  2488. * and present its stdio via a Socket.
  2489. *
  2490. * 'prefix' indicates the prefix that should appear on messages passed
  2491. * to plug_log to provide stderr output from the process.
  2492. */
  2493. Socket *platform_start_subprocess(const char *cmd, Plug *plug,
  2494. const char *prefix);
  2495. /*
  2496. * Define no-op macros for the jump list functions, on platforms that
  2497. * don't support them. (This is a bit of a hack, and it'd be nicer to
  2498. * localise even the calls to those functions into the Windows front
  2499. * end, but it'll do for the moment.)
  2500. */
  2501. #ifndef JUMPLIST_SUPPORTED
  2502. #define add_session_to_jumplist(x) ((void)0)
  2503. #define remove_session_from_jumplist(x) ((void)0)
  2504. #endif
  2505. /* SURROGATE PAIR */
  2506. #ifndef HIGH_SURROGATE_START /* in some toolchains <winnls.h> defines these */
  2507. #define HIGH_SURROGATE_START 0xd800
  2508. #define HIGH_SURROGATE_END 0xdbff
  2509. #define LOW_SURROGATE_START 0xdc00
  2510. #define LOW_SURROGATE_END 0xdfff
  2511. #endif
  2512. /* REGIONAL INDICATOR SYMBOL LETTER A-Z */
  2513. #define IS_REGIONAL_INDICATOR_LETTER(wc) ((unsigned)(wc) - 0x1F1E6U < 26)
  2514. /* These macros exist in the Windows API, so the environment may
  2515. * provide them. If not, define them in terms of the above. */
  2516. #ifndef IS_HIGH_SURROGATE
  2517. #define IS_HIGH_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2518. ((wch) <= HIGH_SURROGATE_END))
  2519. #define IS_LOW_SURROGATE(wch) (((wch) >= LOW_SURROGATE_START) && \
  2520. ((wch) <= LOW_SURROGATE_END))
  2521. #define IS_SURROGATE_PAIR(hs, ls) (IS_HIGH_SURROGATE(hs) && \
  2522. IS_LOW_SURROGATE(ls))
  2523. #endif
  2524. #define IS_SURROGATE(wch) (((wch) >= HIGH_SURROGATE_START) && \
  2525. ((wch) <= LOW_SURROGATE_END))
  2526. #define HIGH_SURROGATE_OF(codept) \
  2527. (HIGH_SURROGATE_START + (((codept) - 0x10000) >> 10))
  2528. #define LOW_SURROGATE_OF(codept) \
  2529. (LOW_SURROGATE_START + (((codept) - 0x10000) & 0x3FF))
  2530. #define FROM_SURROGATES(wch1, wch2) \
  2531. (0x10000 + (((wch1) & 0x3FF) << 10) + ((wch2) & 0x3FF))
  2532. #endif