platform.h 30 KB

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