platform.h 32 KB

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