platform.h 29 KB

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