platform.h 28 KB

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