platform.h 28 KB

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