platform.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * windows/platform.h: Windows-specific inter-module stuff.
  3. */
  4. #ifndef PUTTY_WINDOWS_PLATFORM_H
  5. #define PUTTY_WINDOWS_PLATFORM_H
  6. #include <winsock2.h>
  7. #include <windows.h>
  8. #include <stdio.h> /* for FILENAME_MAX */
  9. /* We use uintptr_t for Win32/Win64 portability, so we should in
  10. * principle include stdint.h, which defines it according to the C
  11. * standard. But older versions of Visual Studio don't provide
  12. * stdint.h at all, but do (non-standardly) define uintptr_t in
  13. * stddef.h. So here we try to make sure _some_ standard header is
  14. * included which defines uintptr_t. */
  15. #include <stddef.h>
  16. #if !HAVE_NO_STDINT_H
  17. #include <stdint.h>
  18. #endif
  19. #include "defs.h"
  20. #include "marshal.h"
  21. #include "tree234.h"
  22. #include "help.h"
  23. #if defined _M_IX86 || defined _M_AMD64
  24. #define BUILDINFO_PLATFORM "x86 Windows"
  25. #elif defined _M_ARM || defined _M_ARM64
  26. #define BUILDINFO_PLATFORM "Arm Windows"
  27. #else
  28. #define BUILDINFO_PLATFORM "Windows"
  29. #endif
  30. #if defined __GNUC__ || defined __clang__
  31. #define THREADLOCAL __thread
  32. #elif defined _MSC_VER
  33. #define THREADLOCAL __declspec(thread)
  34. #else
  35. #error Do not know how to declare thread-local storage with this toolchain
  36. #endif
  37. /* Randomly-chosen dwData value identifying a WM_COPYDATA message as
  38. * being a Pageant transaction */
  39. #define AGENT_COPYDATA_ID 0x804e50ba
  40. struct Filename {
  41. /*
  42. * A Windows Filename stores a path in three formats:
  43. *
  44. * - wchar_t (in Windows UTF-16 encoding). The best format to use
  45. * for actual file API functions, because all legal Windows
  46. * file names are representable.
  47. *
  48. * - char, in the system default codepage. A fallback to use if
  49. * necessary, e.g. in diagnostics written to somewhere that is
  50. * unavoidably encoded _in_ the system codepage.
  51. *
  52. * - char, in UTF-8. An equally general representation to wpath,
  53. * but suitable for keeping in char-typed strings.
  54. */
  55. wchar_t *wpath;
  56. char *cpath, *utf8path;
  57. };
  58. Filename *filename_from_wstr(const wchar_t *str);
  59. FILE *f_open(const Filename *filename, const char *mode, bool isprivate);
  60. #ifndef SUPERSEDE_FONTSPEC_FOR_TESTING
  61. struct FontSpec {
  62. char *name;
  63. bool isbold;
  64. int height;
  65. int charset;
  66. };
  67. struct FontSpec *fontspec_new(
  68. const char *name, bool bold, int height, int charset);
  69. #endif
  70. #ifndef CLEARTYPE_QUALITY
  71. #define CLEARTYPE_QUALITY 5
  72. #endif
  73. #define FONT_QUALITY(fq) ( \
  74. (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
  75. (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
  76. (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
  77. CLEARTYPE_QUALITY)
  78. #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
  79. * wchar_t strings with environment */
  80. #define PLATFORM_CLIPBOARDS(X) \
  81. X(CLIP_SYSTEM, "system clipboard") \
  82. /* end of list */
  83. /*
  84. * Where we can, we use GetWindowLongPtr and friends because they're
  85. * more useful on 64-bit platforms, but they're a relatively recent
  86. * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
  87. * (NB that on some systems, some of these things are available but
  88. * not others...)
  89. */
  90. #ifndef GCLP_HCURSOR
  91. /* GetClassLongPtr and friends */
  92. #undef GetClassLongPtr
  93. #define GetClassLongPtr GetClassLong
  94. #undef SetClassLongPtr
  95. #define SetClassLongPtr SetClassLong
  96. #define GCLP_HCURSOR GCL_HCURSOR
  97. /* GetWindowLongPtr and friends */
  98. #undef GetWindowLongPtr
  99. #define GetWindowLongPtr GetWindowLong
  100. #undef SetWindowLongPtr
  101. #define SetWindowLongPtr SetWindowLong
  102. #undef GWLP_USERDATA
  103. #define GWLP_USERDATA GWL_USERDATA
  104. #undef DWLP_MSGRESULT
  105. #define DWLP_MSGRESULT DWL_MSGRESULT
  106. /* Since we've clobbered the above functions, we should clobber the
  107. * associated type regardless of whether it's defined. */
  108. #undef LONG_PTR
  109. #define LONG_PTR LONG
  110. #endif
  111. #if !HAVE_STRTOUMAX
  112. /* Work around lack of strtoumax in older MSVC libraries */
  113. static inline uintmax_t strtoumax(const char *nptr, char **endptr, int base)
  114. { return _strtoui64(nptr, endptr, base); }
  115. #endif
  116. typedef INT_PTR (*ShinyDlgProc)(HWND hwnd, UINT msg, WPARAM wParam,
  117. LPARAM lParam, void *ctx);
  118. int ShinyDialogBox(HINSTANCE hinst, LPCTSTR tmpl, const char *winclass,
  119. HWND hwndparent, ShinyDlgProc proc, void *ctx);
  120. void ShinyEndDialog(HWND hwnd, int ret);
  121. void centre_window(HWND hwnd);
  122. #ifndef __WINE__
  123. /* Up-to-date Windows headers warn that the unprefixed versions of
  124. * these names are deprecated. */
  125. #define stricmp _stricmp
  126. #define strnicmp _strnicmp
  127. #else
  128. /* Compiling with winegcc, _neither_ version of these functions
  129. * exists. Use the POSIX names. */
  130. #define stricmp strcasecmp
  131. #define strnicmp strncasecmp
  132. #endif
  133. /*
  134. * Dynamically linked functions. These come in two flavours:
  135. *
  136. * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
  137. * so will always dynamically link against exactly what is specified
  138. * in "name". If you're not sure, use this one.
  139. *
  140. * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
  141. * preprocessor definitions like "#define foo bar"; this is principally
  142. * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
  143. * If your function has an argument of type "LPTSTR" or similar, this
  144. * is the variant to use.
  145. * (However, it can't always be used, as it trips over more complicated
  146. * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
  147. *
  148. * (DECL_WINDOWS_FUNCTION works with both these variants.)
  149. */
  150. #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
  151. typedef rettype (WINAPI *t_##name) params; \
  152. linkage t_##name p_##name
  153. /* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to
  154. * define the function pointer in a source file */
  155. #define DEF_WINDOWS_FUNCTION(name) t_##name p_##name
  156. #define GET_WINDOWS_FUNCTION_PP(module, name) \
  157. TYPECHECK((t_##name)NULL == name, \
  158. (p_##name = module ? \
  159. (t_##name) GetProcAddress(module, STR(name)) : NULL))
  160. #define GET_WINDOWS_FUNCTION(module, name) \
  161. TYPECHECK((t_##name)NULL == name, \
  162. (p_##name = module ? \
  163. (t_##name) GetProcAddress(module, #name) : NULL))
  164. #define GET_WINDOWS_FUNCTION_NO_TYPECHECK(module, name) \
  165. (p_##name = module ? \
  166. (t_##name) GetProcAddress(module, #name) : NULL)
  167. #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
  168. #define PUTTY_REG_PARENT "Software\\SimonTatham"
  169. #define PUTTY_REG_PARENT_CHILD "PuTTY"
  170. #define PUTTY_REG_GPARENT "Software"
  171. #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
  172. /* Result values for the jumplist registry functions. */
  173. #define JUMPLISTREG_OK 0
  174. #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
  175. #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
  176. #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
  177. #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
  178. #define JUMPLISTREG_ERROR_INVALID_VALUE 5
  179. #define PUTTY_CHM_FILE "putty.chm"
  180. #define GETTICKCOUNT GetTickCount
  181. #define CURSORBLINK GetCaretBlinkTime()
  182. #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
  183. #define DEFAULT_CODEPAGE CP_ACP
  184. #define USES_VTLINE_HACK
  185. #define CP_UTF8 65001
  186. #define CP_437 437 /* used for test suites */
  187. #define CP_ISO8859_1 0x10001 /* used for test suites */
  188. #ifndef NO_GSSAPI
  189. /*
  190. * GSS-API stuff
  191. */
  192. #define GSS_CC CALLBACK
  193. /*
  194. typedef struct Ssh_gss_buf {
  195. size_t length;
  196. char *value;
  197. } Ssh_gss_buf;
  198. #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
  199. typedef void *Ssh_gss_name;
  200. */
  201. #endif
  202. /*
  203. * The all-important instance handle, saved from WinMain in every GUI
  204. * program and exported for other GUI code to pass back to the Windows
  205. * API.
  206. */
  207. extern HINSTANCE hinst;
  208. /*
  209. * Help file stuff in help.c.
  210. */
  211. void init_help(void);
  212. void shutdown_help(void);
  213. bool has_help(void);
  214. void launch_help(HWND hwnd, const char *topic);
  215. void quit_help(HWND hwnd);
  216. int has_embedded_chm(void); /* 1 = yes, 0 = no, -1 = N/A */
  217. /*
  218. * GUI seat methods in dialog.c, so that the vtable definition in
  219. * window.c can refer to them.
  220. */
  221. SeatPromptResult win_seat_confirm_ssh_host_key(
  222. Seat *seat, const char *host, int port, const char *keytype,
  223. char *keystr, SeatDialogText *text, HelpCtx helpctx,
  224. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  225. SeatPromptResult win_seat_confirm_weak_crypto_primitive(
  226. Seat *seat, SeatDialogText *text,
  227. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  228. SeatPromptResult win_seat_confirm_weak_cached_hostkey(
  229. Seat *seat, SeatDialogText *text,
  230. void (*callback)(void *ctx, SeatPromptResult result), void *ctx);
  231. const SeatDialogPromptDescriptions *win_seat_prompt_descriptions(Seat *seat);
  232. /*
  233. * Windows-specific clipboard helper function shared with dialog.c,
  234. * which takes the data string in the system code page instead of
  235. * Unicode.
  236. */
  237. void write_aclip(HWND hwnd, int clipboard, char *, int);
  238. #define WM_NETEVENT (WM_APP + 5)
  239. /*
  240. * On Windows, we send MA_2CLK as the only event marking the second
  241. * press of a mouse button. Compare unix/platform.h.
  242. */
  243. #define MULTICLICK_ONLY_EVENT 1
  244. /*
  245. * On Windows, data written to the clipboard must be NUL-terminated.
  246. */
  247. #define SELECTION_NUL_TERMINATED 1
  248. /*
  249. * On Windows, copying to the clipboard terminates lines with CRLF.
  250. */
  251. #define SEL_NL { 13, 10 }
  252. /*
  253. * sk_getxdmdata() does not exist under Windows (not that I
  254. * couldn't write it if I wanted to, but I haven't bothered), so
  255. * it's a macro which always returns NULL. With any luck this will
  256. * cause the compiler to notice it can optimise away the
  257. * implementation of XDM-AUTHORIZATION-1 in ssh/x11fwd.c :-)
  258. */
  259. #define sk_getxdmdata(socket, lenp) (NULL)
  260. /*
  261. * File-selector filter strings used in the config box. On Windows,
  262. * these strings are of exactly the type needed to go in
  263. * `lpstrFilter' in an OPENFILENAME structure.
  264. */
  265. typedef const wchar_t *FILESELECT_FILTER_TYPE;
  266. #define FILTER_KEY_FILES (L"PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
  267. L"All Files (*.*)\0*\0\0\0")
  268. #define FILTER_WAVE_FILES (L"Wave Files (*.wav)\0*.WAV\0" \
  269. L"All Files (*.*)\0*\0\0\0")
  270. #define FILTER_DYNLIB_FILES (L"Dynamic Library Files (*.dll)\0*.dll\0" \
  271. L"All Files (*.*)\0*\0\0\0")
  272. /* char-based versions of the above, for outlying uses of file selectors. */
  273. #define FILTER_KEY_FILES_C ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
  274. "All Files (*.*)\0*\0\0\0")
  275. #define FILTER_WAVE_FILES_C ("Wave Files (*.wav)\0*.WAV\0" \
  276. "All Files (*.*)\0*\0\0\0")
  277. #define FILTER_DYNLIB_FILES_C ("Dynamic Library Files (*.dll)\0*.dll\0" \
  278. "All Files (*.*)\0*\0\0\0")
  279. /*
  280. * Exports from network.c.
  281. */
  282. /* Report an event notification from WSA*Select */
  283. void select_result(WPARAM, LPARAM);
  284. /* Enumerate all currently live OS-level SOCKETs */
  285. SOCKET first_socket(int *);
  286. SOCKET next_socket(int *);
  287. /* Ask network.c whether we currently want to try to write to a SOCKET */
  288. bool socket_writable(SOCKET skt);
  289. /* Force a refresh of the SOCKET list by re-calling do_select for each one */
  290. void socket_reselect_all(void);
  291. /* Make a SockAddr which just holds a named pipe address. */
  292. SockAddr *sk_namedpipe_addr(const char *pipename);
  293. /* Turn a WinSock error code into a string. */
  294. const char *winsock_error_string(int error);
  295. Socket *sk_newlistener_unix(const char *socketpath, Plug *plug);
  296. /*
  297. * network.c dynamically loads WinSock 2 or WinSock 1 depending on
  298. * what it can get, which means any WinSock routines used outside
  299. * that module must be exported from it as function pointers. So
  300. * here they are.
  301. */
  302. DECL_WINDOWS_FUNCTION(extern, int, WSAAsyncSelect,
  303. (SOCKET, HWND, u_int, LONG));
  304. DECL_WINDOWS_FUNCTION(extern, int, WSAEventSelect,
  305. (SOCKET, WSAEVENT, LONG));
  306. DECL_WINDOWS_FUNCTION(extern, int, WSAGetLastError, (void));
  307. DECL_WINDOWS_FUNCTION(extern, int, WSAEnumNetworkEvents,
  308. (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
  309. #ifdef NEED_DECLARATION_OF_SELECT
  310. /* This declaration is protected by an ifdef for the sake of building
  311. * against winelib, in which you have to include winsock2.h before
  312. * stdlib.h so that the right fd_set type gets defined. It would be a
  313. * pain to do that throughout this codebase, so instead I arrange that
  314. * only a modules actually needing to use (or define, or initialise)
  315. * this function pointer will see its declaration, and _those_ modules
  316. * - which will be Windows-specific anyway - can take more care. */
  317. DECL_WINDOWS_FUNCTION(extern, int, select,
  318. (int, fd_set FAR *, fd_set FAR *,
  319. fd_set FAR *, const struct timeval FAR *));
  320. #endif
  321. /*
  322. * Implemented differently depending on the client of network.c, and
  323. * called by network.c to turn on or off WSA*Select for a given socket.
  324. */
  325. const char *do_select(SOCKET skt, bool enable);
  326. /*
  327. * Exports from select-{gui,cli}.c, each of which provides an
  328. * implementation of do_select.
  329. */
  330. void winselgui_set_hwnd(HWND hwnd);
  331. void winselgui_clear_hwnd(void);
  332. void winselgui_response(WPARAM wParam, LPARAM lParam);
  333. void winselcli_setup(void);
  334. SOCKET winselcli_unique_socket(void);
  335. extern HANDLE winselcli_event;
  336. /*
  337. * Network-subsystem-related functions provided in other Windows modules.
  338. */
  339. Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
  340. SockAddr *addr, int port, Plug *plug,
  341. bool overlapped); /* winhsock */
  342. Socket *make_deferred_handle_socket(DeferredSocketOpener *opener,
  343. SockAddr *addr, int port, Plug *plug);
  344. void setup_handle_socket(Socket *s, HANDLE send_H, HANDLE recv_H,
  345. HANDLE stderr_H, bool overlapped);
  346. void handle_socket_set_psb_prefix(Socket *s, const char *prefix);
  347. Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
  348. Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */
  349. /* A lower-level function in named-pipe-client.c, which does most of
  350. * the work of new_named_pipe_client (including checking the ownership
  351. * of what it's connected to), but returns a plain HANDLE instead of
  352. * wrapping it into a Socket. */
  353. HANDLE connect_to_named_pipe(const char *pipename, char **err);
  354. /*
  355. * Exports from controls.c.
  356. */
  357. struct ctlpos {
  358. HWND hwnd;
  359. WPARAM font;
  360. int dlu4inpix;
  361. int ypos, width;
  362. int xoff;
  363. int boxystart, boxid;
  364. const char *boxtext;
  365. };
  366. void init_common_controls(void); /* also does some DLL-loading */
  367. /*
  368. * Exports from utils.
  369. */
  370. typedef struct filereq_tag filereq; /* cwd for file requester */
  371. bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
  372. bool request_file_w(filereq *state, OPENFILENAMEW *of,
  373. bool preserve, bool save);
  374. filereq *filereq_new(void);
  375. void filereq_free(filereq *state);
  376. void pgp_fingerprints_msgbox(HWND owner);
  377. int message_box(HWND owner, LPCTSTR text, LPCTSTR caption, DWORD style,
  378. bool utf8, DWORD helpctxid);
  379. void MakeDlgItemBorderless(HWND parent, int id);
  380. char *GetDlgItemText_alloc(HWND hwnd, int id);
  381. wchar_t *GetDlgItemTextW_alloc(HWND hwnd, int id);
  382. /*
  383. * The split_into_argv functions take a single string 'cmdline' (char
  384. * or wide) to split up into arguments. They return an argc and argv
  385. * pair, and also 'argstart', an array of pointers into the original
  386. * command line, pointing at the place where each output argument
  387. * begins. (Useful for retrieving the tail of the original command
  388. * line corresponding to a certain argument onwards, or identifying a
  389. * section of the original command line to blank out for privacy.)
  390. *
  391. * If the command line includes the program name (e.g. if it was
  392. * returned from GetCommandLine()), set includes_program_name=true. If
  393. * it doesn't (e.g. it was the arguments string received by WinMain),
  394. * set that flag to false. This affects the rules for argument
  395. * splitting, which is done differently in the program name
  396. * (specifically, \ isn't special, and won't escape ").
  397. *
  398. * Mutability: the argv[] words are in fresh dynamically allocated
  399. * memory, so you can write into them safely. The original cmdline is
  400. * passed in as a const pointer, and not modified in this function.
  401. * But the pointers into that string written into argstart have the
  402. * type of a mutable char *. Similarly to strchr, this is due to the
  403. * limitation of C that you can't specify argstart as having the same
  404. * constness as cmdline: the idea is that you either pass a
  405. * non-mutable cmdline and promise not to write through the argstart
  406. * pointers, of you pass a mutable one and are free to write through
  407. * it.
  408. *
  409. * Allocation: argv and argstart are dynamically allocated. There's
  410. * also a dynamically allocated string behind the scenes storing the
  411. * actual strings. argv[0] guarantees to point at the first character
  412. * of that. So to free all the memory allocated by this function, you
  413. * must free argv[0], then argv, and also argstart.
  414. */
  415. void split_into_argv(const char *cmdline, bool includes_program_name,
  416. int *argc, char ***argv, char ***argstart);
  417. void split_into_argv_w(const wchar_t *cmdline, bool includes_program_name,
  418. int *argc, wchar_t ***argv, wchar_t ***argstart);
  419. /*
  420. * Private structure for prefslist state. Only in the header file
  421. * so that we can delegate allocation to callers.
  422. */
  423. struct prefslist {
  424. int listid, upbid, dnbid;
  425. int srcitem;
  426. int dummyitem;
  427. bool dragging;
  428. };
  429. /*
  430. * This structure is passed to event handler functions as the `dlg'
  431. * parameter, and hence is passed back to winctrls access functions.
  432. */
  433. struct dlgparam {
  434. HWND hwnd; /* the hwnd of the dialog box */
  435. struct winctrls *controltrees[8]; /* can have several of these */
  436. int nctrltrees;
  437. char *wintitle; /* title of actual window */
  438. char *errtitle; /* title of error sub-messageboxes */
  439. void *data; /* data to pass in refresh events */
  440. dlgcontrol *focused, *lastfocused; /* which ctrl has focus now/before */
  441. bool shortcuts[128]; /* track which shortcuts in use */
  442. bool coloursel_wanted; /* has an event handler asked for
  443. * a colour selector? */
  444. struct {
  445. unsigned char r, g, b; /* 0-255 */
  446. bool ok;
  447. } coloursel_result;
  448. tree234 *privdata; /* stores per-control private data */
  449. bool ended; /* has the dialog been ended? */
  450. int endresult; /* and if so, what was the result? */
  451. bool fixed_pitch_fonts; /* are we constrained to fixed fonts? */
  452. };
  453. /*
  454. * Exports from controls.c.
  455. */
  456. void ctlposinit(struct ctlpos *cp, HWND hwnd,
  457. int leftborder, int rightborder, int topborder);
  458. HWND doctl(struct ctlpos *cp, RECT r, const char *wclass, int wstyle,
  459. int exstyle, const char *wtext, int wid);
  460. void bartitle(struct ctlpos *cp, const char *name, int id);
  461. void beginbox(struct ctlpos *cp, const char *name, int idbox);
  462. void endbox(struct ctlpos *cp);
  463. void editboxfw(struct ctlpos *cp, bool password, bool readonly,
  464. const char *text, int staticid, int editid);
  465. void radioline(struct ctlpos *cp, const char *text, int id, int nacross, ...);
  466. void bareradioline(struct ctlpos *cp, int nacross, ...);
  467. void radiobig(struct ctlpos *cp, const char *text, int id, ...);
  468. void checkbox(struct ctlpos *cp, const char *text, int id);
  469. void button(struct ctlpos *cp, const char *btext, int bid, bool defbtn);
  470. void statictext(struct ctlpos *cp, const char *text, int lines, int id);
  471. void staticbtn(struct ctlpos *cp, const char *stext, int sid,
  472. const char *btext, int bid);
  473. void static2btn(struct ctlpos *cp, const char *stext, int sid,
  474. const char *btext1, int bid1, const char *btext2, int bid2);
  475. void staticedit(struct ctlpos *cp, const char *stext,
  476. int sid, int eid, int percentedit);
  477. void staticddl(struct ctlpos *cp, const char *stext,
  478. int sid, int lid, int percentlist);
  479. void combobox(struct ctlpos *cp, const char *text, int staticid, int listid);
  480. void staticpassedit(struct ctlpos *cp, const char *stext,
  481. int sid, int eid, int percentedit);
  482. void bigeditctrl(struct ctlpos *cp, const char *stext,
  483. int sid, int eid, int lines);
  484. void ersatztab(struct ctlpos *cp, const char *stext, int sid, int lid,
  485. int s2id);
  486. void editbutton(struct ctlpos *cp, const char *stext, int sid,
  487. int eid, const char *btext, int bid);
  488. void sesssaver(struct ctlpos *cp, const char *text,
  489. int staticid, int editid, int listid, ...);
  490. void envsetter(struct ctlpos *cp, const char *stext, int sid,
  491. const char *e1stext, int e1sid, int e1id,
  492. const char *e2stext, int e2sid, int e2id,
  493. int listid, const char *b1text, int b1id,
  494. const char *b2text, int b2id);
  495. void charclass(struct ctlpos *cp, const char *stext, int sid, int listid,
  496. const char *btext, int bid, int eid, const char *s2text,
  497. int s2id);
  498. void colouredit(struct ctlpos *cp, const char *stext, int sid, int listid,
  499. const char *btext, int bid, ...);
  500. void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
  501. const char *stext, int sid, int listid, int upbid, int dnbid);
  502. int handle_prefslist(struct prefslist *hdl,
  503. int *array, int maxmemb,
  504. bool is_dlmsg, HWND hwnd,
  505. WPARAM wParam, LPARAM lParam);
  506. void progressbar(struct ctlpos *cp, int id);
  507. void fwdsetter(struct ctlpos *cp, int listid, const char *stext, int sid,
  508. const char *e1stext, int e1sid, int e1id,
  509. const char *e2stext, int e2sid, int e2id,
  510. const char *btext, int bid,
  511. const char *r1text, int r1id, const char *r2text, int r2id);
  512. void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
  513. bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
  514. void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag);
  515. #define MAX_SHORTCUTS_PER_CTRL 16
  516. /*
  517. * This structure is what's stored for each `dlgcontrol' in the
  518. * portable-dialog interface.
  519. */
  520. struct winctrl {
  521. dlgcontrol *ctrl;
  522. /*
  523. * The control may have several components at the Windows
  524. * level, with different dialog IDs. To avoid needing N
  525. * separate platformsidectrl structures (which could be stored
  526. * separately in a tree234 so that lookup by ID worked), we
  527. * impose the constraint that those IDs must be in a contiguous
  528. * block.
  529. */
  530. int base_id;
  531. int num_ids;
  532. /*
  533. * For vertical alignment, the id of a particular representative
  534. * control that has the y-extent of the sensible part of the
  535. * control.
  536. */
  537. int align_id;
  538. /*
  539. * Remember what keyboard shortcuts were used by this control,
  540. * so that when we remove it again we can take them out of the
  541. * list in the dlgparam.
  542. */
  543. char shortcuts[MAX_SHORTCUTS_PER_CTRL];
  544. /*
  545. * Some controls need a piece of allocated memory in which to
  546. * store temporary data about the control.
  547. */
  548. void *data;
  549. };
  550. /*
  551. * And this structure holds a set of the above, in two separate
  552. * tree234s so that it can find an item by `dlgcontrol' or by
  553. * dialog ID.
  554. */
  555. struct winctrls {
  556. tree234 *byctrl, *byid;
  557. };
  558. struct controlset;
  559. struct controlbox;
  560. void winctrl_init(struct winctrls *);
  561. void winctrl_cleanup(struct winctrls *);
  562. void winctrl_add(struct winctrls *, struct winctrl *);
  563. void winctrl_remove(struct winctrls *, struct winctrl *);
  564. struct winctrl *winctrl_findbyctrl(struct winctrls *, dlgcontrol *);
  565. struct winctrl *winctrl_findbyid(struct winctrls *, int);
  566. struct winctrl *winctrl_findbyindex(struct winctrls *, int);
  567. void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
  568. struct ctlpos *cp, struct controlset *s, int *id);
  569. bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
  570. WPARAM wParam, LPARAM lParam);
  571. void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
  572. bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
  573. void dp_init(struct dlgparam *dp);
  574. void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
  575. void dp_cleanup(struct dlgparam *dp);
  576. /*
  577. * Exports from config.c.
  578. */
  579. void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
  580. bool midsession, int protocol);
  581. /*
  582. * Exports from dialog.c.
  583. */
  584. void defuse_showwindow(void);
  585. bool do_config(Conf *);
  586. bool do_reconfig(HWND, Conf *, int);
  587. void showeventlog(HWND);
  588. void showabout(HWND);
  589. void force_normal(HWND hwnd);
  590. void modal_about_box(HWND hwnd);
  591. void show_help(HWND hwnd);
  592. HWND event_log_window(void);
  593. /*
  594. * Exports from utils.
  595. */
  596. extern DWORD osMajorVersion, osMinorVersion, osPlatformId;
  597. void init_winver(void);
  598. void dll_hijacking_protection(void);
  599. const char *get_system_dir(void);
  600. HMODULE load_system32_dll(const char *libname);
  601. const char *win_strerror(int error);
  602. bool should_have_security(void);
  603. void restrict_process_acl(void);
  604. bool restricted_acl(void);
  605. void escape_registry_key(const char *in, strbuf *out);
  606. void unescape_registry_key(const char *in, strbuf *out);
  607. bool is_console_handle(HANDLE);
  608. /* A few pieces of up-to-date Windows API definition needed for older
  609. * compilers. */
  610. #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
  611. #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
  612. #endif
  613. #ifndef LOAD_LIBRARY_SEARCH_USER_DIRS
  614. #define LOAD_LIBRARY_SEARCH_USER_DIRS 0x00000400
  615. #endif
  616. #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
  617. #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100
  618. #endif
  619. #ifndef DLL_DIRECTORY_COOKIE
  620. typedef PVOID DLL_DIRECTORY_COOKIE;
  621. DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory);
  622. #endif
  623. /*
  624. * Exports from sizetip.c.
  625. */
  626. void UpdateSizeTip(HWND src, int cx, int cy);
  627. void EnableSizeTip(bool bEnable);
  628. /*
  629. * Exports from unicode.c.
  630. */
  631. void init_ucs(Conf *, struct unicode_data *);
  632. /*
  633. * Exports from handle-io.c.
  634. */
  635. #define HANDLE_FLAG_OVERLAPPED 1
  636. #define HANDLE_FLAG_IGNOREEOF 2
  637. #define HANDLE_FLAG_UNITBUFFER 4
  638. struct handle;
  639. typedef size_t (*handle_inputfn_t)(
  640. struct handle *h, const void *data, size_t len, int err);
  641. typedef void (*handle_outputfn_t)(
  642. struct handle *h, size_t new_backlog, int err, bool close);
  643. struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
  644. void *privdata, int flags);
  645. struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
  646. void *privdata, int flags);
  647. size_t handle_write(struct handle *h, const void *data, size_t len);
  648. void handle_write_eof(struct handle *h);
  649. void handle_free(struct handle *h);
  650. void handle_unthrottle(struct handle *h, size_t backlog);
  651. size_t handle_backlog(struct handle *h);
  652. void *handle_get_privdata(struct handle *h);
  653. /* Analogue of stdio_sink in marshal.h, for a Windows handle */
  654. struct handle_sink {
  655. struct handle *h;
  656. BinarySink_IMPLEMENTATION;
  657. };
  658. void handle_sink_init(handle_sink *sink, struct handle *h);
  659. /*
  660. * Exports from handle-wait.c.
  661. */
  662. typedef struct HandleWait HandleWait;
  663. typedef void (*handle_wait_callback_fn_t)(void *);
  664. HandleWait *add_handle_wait(HANDLE h, handle_wait_callback_fn_t callback,
  665. void *callback_ctx);
  666. void delete_handle_wait(HandleWait *hw);
  667. typedef struct HandleWaitList {
  668. HANDLE handles[MAXIMUM_WAIT_OBJECTS];
  669. int nhandles;
  670. } HandleWaitList;
  671. HandleWaitList *get_handle_wait_list(void);
  672. void handle_wait_activate(HandleWaitList *hwl, int index);
  673. void handle_wait_list_free(HandleWaitList *hwl);
  674. /*
  675. * Pageant-related pathnames.
  676. */
  677. char *agent_mutex_name(void);
  678. char *agent_named_pipe_name(void);
  679. /*
  680. * Exports from serial.c.
  681. */
  682. extern const struct BackendVtable serial_backend;
  683. /*
  684. * Exports from jump-list.c.
  685. */
  686. #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
  687. void add_session_to_jumplist(const char * const sessionname);
  688. void remove_session_from_jumplist(const char * const sessionname);
  689. void clear_jumplist(void);
  690. bool set_explicit_app_user_model_id(void);
  691. /*
  692. * Exports from noise.c.
  693. */
  694. bool win_read_random(void *buf, unsigned wanted); /* returns true on success */
  695. /*
  696. * Extra functions in storage.c over and above the interface in
  697. * storage.h.
  698. *
  699. * These functions manipulate the Registry section which mirrors the
  700. * current Windows 7 jump list. (Because the real jump list storage is
  701. * write-only, we need to keep another copy of whatever we put in it,
  702. * so that we can put in a slightly modified version the next time.)
  703. */
  704. /* Adds a saved session to the registry jump list mirror. 'item' is a
  705. * string naming a saved session. */
  706. int add_to_jumplist_registry(const char *item);
  707. /* Removes an item from the registry jump list mirror. */
  708. int remove_from_jumplist_registry(const char *item);
  709. /* Returns the current jump list entries from the registry. Caller
  710. * must free the returned pointer, which points to a contiguous
  711. * sequence of NUL-terminated strings in memory, terminated with an
  712. * empty one. */
  713. char *get_jumplist_registry_entries(void);
  714. /*
  715. * Windows clipboard-UI wording.
  716. */
  717. #define CLIPNAME_IMPLICIT "Last selected text"
  718. #define CLIPNAME_EXPLICIT "System clipboard"
  719. #define CLIPNAME_EXPLICIT_OBJECT "system clipboard"
  720. /* These defaults are the ones PuTTY has historically had */
  721. #define CLIPUI_DEFAULT_AUTOCOPY true
  722. #define CLIPUI_DEFAULT_MOUSE CLIPUI_EXPLICIT
  723. #define CLIPUI_DEFAULT_INS CLIPUI_EXPLICIT
  724. /* In utils */
  725. HKEY open_regkey_fn(bool create, bool write, HKEY base, const char *path, ...);
  726. #define open_regkey_ro(base, ...) \
  727. open_regkey_fn(false, false, base, __VA_ARGS__, (const char *)NULL)
  728. #define open_regkey_rw(base, ...) \
  729. open_regkey_fn(false, true, base, __VA_ARGS__, (const char *)NULL)
  730. #define create_regkey(base, ...) \
  731. open_regkey_fn(true, true, base, __VA_ARGS__, (const char *)NULL)
  732. void close_regkey(HKEY key);
  733. void del_regkey(HKEY key, const char *name);
  734. char *enum_regkey(HKEY key, int index);
  735. bool get_reg_dword(HKEY key, const char *name, DWORD *out);
  736. bool put_reg_dword(HKEY key, const char *name, DWORD value);
  737. char *get_reg_sz(HKEY key, const char *name);
  738. bool put_reg_sz(HKEY key, const char *name, const char *str);
  739. strbuf *get_reg_multi_sz(HKEY key, const char *name);
  740. bool put_reg_multi_sz(HKEY key, const char *name, strbuf *str);
  741. char *get_reg_sz_simple(HKEY key, const char *name, const char *leaf);
  742. /* In cliloop.c */
  743. typedef bool (*cliloop_pre_t)(void *vctx, const HANDLE **extra_handles,
  744. size_t *n_extra_handles);
  745. typedef bool (*cliloop_post_t)(void *vctx, size_t extra_handle_index);
  746. void cli_main_loop(cliloop_pre_t pre, cliloop_post_t post, void *ctx);
  747. bool cliloop_null_pre(void *vctx, const HANDLE **, size_t *);
  748. bool cliloop_null_post(void *vctx, size_t);
  749. extern const struct BackendVtable conpty_backend;
  750. /* Functions that parametrise window.c between PuTTY and pterm */
  751. void gui_term_process_cmdline(Conf *conf, char *cmdline);
  752. const struct BackendVtable *backend_vt_from_conf(Conf *conf);
  753. const wchar_t *get_app_user_model_id(void);
  754. /* And functions in window.c that those files call back to */
  755. char *handle_restrict_acl_cmdline_prefix(char *cmdline);
  756. bool handle_special_sessionname_cmdline(char *cmdline, Conf *conf);
  757. bool handle_special_filemapping_cmdline(char *cmdline, Conf *conf);
  758. /* network.c: network error reporting helpers taking OS error code */
  759. void plug_closing_system_error(Plug *plug, DWORD error);
  760. void plug_closing_winsock_error(Plug *plug, DWORD error);
  761. SeatPromptResult make_spr_sw_abort_winerror(const char *prefix, DWORD error);
  762. HANDLE lock_interprocess_mutex(const char *mutexname, char **error);
  763. void unlock_interprocess_mutex(HANDLE mutex);
  764. typedef void (*aux_opt_error_fn_t)(const char *, ...);
  765. typedef struct AuxMatchOpt {
  766. CmdlineArgList *arglist;
  767. size_t index;
  768. bool doing_opts;
  769. aux_opt_error_fn_t error;
  770. } AuxMatchOpt;
  771. AuxMatchOpt aux_match_opt_init(aux_opt_error_fn_t opt_error);
  772. bool aux_match_arg(AuxMatchOpt *amo, CmdlineArg **val);
  773. bool aux_match_opt(AuxMatchOpt *amo, CmdlineArg **val,
  774. const char *optname, ...);
  775. bool aux_match_done(AuxMatchOpt *amo);
  776. char *save_screenshot(HWND hwnd, Filename *outfile);
  777. void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend);
  778. void setup_gui_timing(void);
  779. /* Windows-specific extra functions in cmdline_arg.c */
  780. CmdlineArgList *cmdline_arg_list_from_GetCommandLineW(void);
  781. const wchar_t *cmdline_arg_remainder_wide(CmdlineArg *);
  782. char *cmdline_arg_remainder_acp(CmdlineArg *);
  783. char *cmdline_arg_remainder_utf8(CmdlineArg *);
  784. CmdlineArg *cmdline_arg_from_utf8(CmdlineArgList *list, const char *string);
  785. #endif /* PUTTY_WINDOWS_PLATFORM_H */