platform.h 34 KB

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