winstuff.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * winstuff.h: Windows-specific inter-module stuff.
  3. */
  4. #ifndef PUTTY_WINSTUFF_H
  5. #define PUTTY_WINSTUFF_H
  6. #ifndef AUTO_WINSOCK
  7. #include <winsock2.h>
  8. #endif
  9. #include <windows.h>
  10. #include <stdio.h> /* for FILENAME_MAX */
  11. /* We use uintptr_t for Win32/Win64 portability, so we should in
  12. * principle include stdint.h, which defines it according to the C
  13. * standard. But older versions of Visual Studio - including the one
  14. * used for official PuTTY builds as of 2015-09-28 - don't provide
  15. * stdint.h at all, but do (non-standardly) define uintptr_t in
  16. * stddef.h. So here we try to make sure _some_ standard header is
  17. * included which defines uintptr_t. */
  18. #include <stddef.h>
  19. #if !defined _MSC_VER || _MSC_VER >= 1600 || defined __clang__
  20. #include <stdint.h>
  21. #endif
  22. #include "defs.h"
  23. #include "marshal.h"
  24. #include "tree234.h"
  25. #ifndef MPEXT
  26. #include "winhelp.h"
  27. #endif
  28. #if defined _M_IX86 || defined _M_AMD64
  29. #define BUILDINFO_PLATFORM "x86 Windows"
  30. #elif defined _M_ARM || defined _M_ARM64
  31. #define BUILDINFO_PLATFORM "Arm Windows"
  32. #else
  33. #define BUILDINFO_PLATFORM "Windows"
  34. #endif
  35. 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. #define BOXFLAGS DLGWINDOWEXTRA
  94. #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
  95. #define DF_END 0x0001
  96. #ifndef __WINE__
  97. #ifdef MPEXT
  98. /* use them as is in bcb */
  99. #else
  100. /* Up-to-date Windows headers warn that the unprefixed versions of
  101. * these names are deprecated. */
  102. #define stricmp _stricmp
  103. #define strnicmp _strnicmp
  104. #endif
  105. #else
  106. /* Compiling with winegcc, _neither_ version of these functions
  107. * exists. Use the POSIX names. */
  108. #define stricmp strcasecmp
  109. #define strnicmp strncasecmp
  110. #endif
  111. #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in sshshare.c */
  112. /*
  113. * Dynamically linked functions. These come in two flavours:
  114. *
  115. * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
  116. * so will always dynamically link against exactly what is specified
  117. * in "name". If you're not sure, use this one.
  118. *
  119. * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
  120. * preprocessor definitions like "#define foo bar"; this is principally
  121. * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
  122. * If your function has an argument of type "LPTSTR" or similar, this
  123. * is the variant to use.
  124. * (However, it can't always be used, as it trips over more complicated
  125. * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
  126. *
  127. * (DECL_WINDOWS_FUNCTION works with both these variants.)
  128. */
  129. #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
  130. typedef rettype (WINAPI *t_##name) params; \
  131. linkage t_##name p_##name
  132. /* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to
  133. * define the function pointer in a source file */
  134. #define DEF_WINDOWS_FUNCTION(name) t_##name p_##name
  135. #define STR1(x) #x
  136. #define STR(x) STR1(x)
  137. #define GET_WINDOWS_FUNCTION_PP(module, name) \
  138. TYPECHECK((t_##name)NULL == name, \
  139. (p_##name = module ? \
  140. (t_##name) GetProcAddress(module, STR(name)) : NULL))
  141. #define GET_WINDOWS_FUNCTION(module, name) \
  142. TYPECHECK((t_##name)NULL == name, \
  143. (p_##name = module ? \
  144. (t_##name) GetProcAddress(module, #name) : NULL))
  145. #define GET_WINDOWS_FUNCTION_NO_TYPECHECK(module, name) \
  146. (p_##name = module ? \
  147. (t_##name) GetProcAddress(module, #name) : NULL)
  148. #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
  149. #define PUTTY_REG_PARENT "Software\\SimonTatham"
  150. #define PUTTY_REG_PARENT_CHILD "PuTTY"
  151. #define PUTTY_REG_GPARENT "Software"
  152. #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
  153. /* Result values for the jumplist registry functions. */
  154. #define JUMPLISTREG_OK 0
  155. #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
  156. #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
  157. #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
  158. #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
  159. #define JUMPLISTREG_ERROR_INVALID_VALUE 5
  160. #define PUTTY_CHM_FILE "putty.chm"
  161. #define GETTICKCOUNT GetTickCount
  162. #define CURSORBLINK GetCaretBlinkTime()
  163. #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
  164. #define DEFAULT_CODEPAGE CP_ACP
  165. #define USES_VTLINE_HACK
  166. #ifndef NO_GSSAPI
  167. /*
  168. * GSS-API stuff
  169. */
  170. #define GSS_CC CALLBACK
  171. /*
  172. typedef struct Ssh_gss_buf {
  173. size_t length;
  174. char *value;
  175. } Ssh_gss_buf;
  176. #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
  177. typedef void *Ssh_gss_name;
  178. */
  179. #endif
  180. /*
  181. * The all-important instance handle, saved from WinMain in every GUI
  182. * program and exported for other GUI code to pass back to the Windows
  183. * API.
  184. */
  185. extern HINSTANCE hinst;
  186. /*
  187. * Help file stuff in winhelp.c.
  188. */
  189. void init_help(void);
  190. void shutdown_help(void);
  191. bool has_help(void);
  192. void launch_help(HWND hwnd, const char *topic);
  193. void quit_help(HWND hwnd);
  194. int has_embedded_chm(void); /* 1 = yes, 0 = no, -1 = N/A */
  195. /*
  196. * GUI seat methods in windlg.c, so that the vtable definition in
  197. * window.c can refer to them.
  198. */
  199. int win_seat_verify_ssh_host_key(
  200. Seat *seat, const char *host, int port, const char *keytype,
  201. char *keystr, const char *keydisp, char **key_fingerprints,
  202. void (*callback)(void *ctx, int result), void *ctx);
  203. int win_seat_confirm_weak_crypto_primitive(
  204. Seat *seat, const char *algtype, const char *algname,
  205. void (*callback)(void *ctx, int result), void *ctx);
  206. int win_seat_confirm_weak_cached_hostkey(
  207. Seat *seat, const char *algname, const char *betteralgs,
  208. void (*callback)(void *ctx, int result), void *ctx);
  209. /*
  210. * Windows-specific clipboard helper function shared with windlg.c,
  211. * which takes the data string in the system code page instead of
  212. * Unicode.
  213. */
  214. void write_aclip(int clipboard, char *, int, bool);
  215. #define WM_NETEVENT (WM_APP + 5)
  216. /*
  217. * On Windows, we send MA_2CLK as the only event marking the second
  218. * press of a mouse button. Compare unix.h.
  219. */
  220. #define MULTICLICK_ONLY_EVENT 1
  221. /*
  222. * On Windows, data written to the clipboard must be NUL-terminated.
  223. */
  224. #define SELECTION_NUL_TERMINATED 1
  225. /*
  226. * On Windows, copying to the clipboard terminates lines with CRLF.
  227. */
  228. #define SEL_NL { 13, 10 }
  229. /*
  230. * sk_getxdmdata() does not exist under Windows (not that I
  231. * couldn't write it if I wanted to, but I haven't bothered), so
  232. * it's a macro which always returns NULL. With any luck this will
  233. * cause the compiler to notice it can optimise away the
  234. * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
  235. */
  236. #define sk_getxdmdata(socket, lenp) (NULL)
  237. /*
  238. * File-selector filter strings used in the config box. On Windows,
  239. * these strings are of exactly the type needed to go in
  240. * `lpstrFilter' in an OPENFILENAME structure.
  241. */
  242. #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
  243. "All Files (*.*)\0*\0\0\0")
  244. #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
  245. "All Files (*.*)\0*\0\0\0")
  246. #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
  247. "All Files (*.*)\0*\0\0\0")
  248. /*
  249. * Exports from winnet.c.
  250. */
  251. /* Report an event notification from WSA*Select */
  252. void select_result(WPARAM, LPARAM);
  253. /* Enumerate all currently live OS-level SOCKETs */
  254. SOCKET first_socket(int *);
  255. SOCKET next_socket(int *);
  256. /* Ask winnet.c whether we currently want to try to write to a SOCKET */
  257. bool socket_writable(SOCKET skt);
  258. /* Force a refresh of the SOCKET list by re-calling do_select for each one */
  259. void socket_reselect_all(void);
  260. /* Make a SockAddr which just holds a named pipe address. */
  261. SockAddr *sk_namedpipe_addr(const char *pipename);
  262. /* Turn a WinSock error code into a string. */
  263. const char *winsock_error_string(int error);
  264. /*
  265. * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
  266. * what it can get, which means any WinSock routines used outside
  267. * that module must be exported from it as function pointers. So
  268. * here they are.
  269. */
  270. DECL_WINDOWS_FUNCTION(extern, int, WSAAsyncSelect,
  271. (SOCKET, HWND, u_int, long));
  272. DECL_WINDOWS_FUNCTION(extern, int, WSAEventSelect,
  273. (SOCKET, WSAEVENT, long));
  274. DECL_WINDOWS_FUNCTION(extern, int, WSAGetLastError, (void));
  275. DECL_WINDOWS_FUNCTION(extern, int, WSAEnumNetworkEvents,
  276. (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
  277. #ifdef NEED_DECLARATION_OF_SELECT
  278. /* This declaration is protected by an ifdef for the sake of building
  279. * against winelib, in which you have to include winsock2.h before
  280. * stdlib.h so that the right fd_set type gets defined. It would be a
  281. * pain to do that throughout this codebase, so instead I arrange that
  282. * only a modules actually needing to use (or define, or initialise)
  283. * this function pointer will see its declaration, and _those_ modules
  284. * - which will be Windows-specific anyway - can take more care. */
  285. DECL_WINDOWS_FUNCTION(extern, int, select,
  286. (int, fd_set FAR *, fd_set FAR *,
  287. fd_set FAR *, const struct timeval FAR *));
  288. #endif
  289. /*
  290. * Implemented differently depending on the client of winnet.c, and
  291. * called by winnet.c to turn on or off WSA*Select for a given socket.
  292. */
  293. const char *do_select(Plug * plug, SOCKET skt, bool enable); // WINSCP
  294. /*
  295. * Exports from winselgui.c and winselcli.c, each of which provides an
  296. * implementation of do_select.
  297. */
  298. void winselgui_set_hwnd(HWND hwnd);
  299. void winselgui_clear_hwnd(void);
  300. void winselcli_setup(void);
  301. SOCKET winselcli_unique_socket(void);
  302. extern HANDLE winselcli_event;
  303. /*
  304. * Network-subsystem-related functions provided in other Windows modules.
  305. */
  306. Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
  307. Plug *plug, bool overlapped); /* winhsock */
  308. Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
  309. Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */
  310. /* A lower-level function in winnpc.c, which does most of the work of
  311. * new_named_pipe_client (including checking the ownership of what
  312. * it's connected to), but returns a plain HANDLE instead of wrapping
  313. * it into a Socket. */
  314. HANDLE connect_to_named_pipe(const char *pipename, char **err);
  315. /*
  316. * Exports from winctrls.c.
  317. */
  318. struct ctlpos {
  319. HWND hwnd;
  320. WPARAM font;
  321. int dlu4inpix;
  322. int ypos, width;
  323. int xoff;
  324. int boxystart, boxid;
  325. char *boxtext;
  326. };
  327. void init_common_controls(void); /* also does some DLL-loading */
  328. /*
  329. * Exports from winutils.c.
  330. */
  331. typedef struct filereq_tag filereq; /* cwd for file requester */
  332. bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
  333. filereq *filereq_new(void);
  334. void filereq_free(filereq *state);
  335. void pgp_fingerprints_msgbox(HWND owner);
  336. int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
  337. DWORD style, DWORD helpctxid);
  338. void MakeDlgItemBorderless(HWND parent, int id);
  339. char *GetDlgItemText_alloc(HWND hwnd, int id);
  340. void split_into_argv(char *, int *, char ***, char ***);
  341. /*
  342. * Private structure for prefslist state. Only in the header file
  343. * so that we can delegate allocation to callers.
  344. */
  345. struct prefslist {
  346. int listid, upbid, dnbid;
  347. int srcitem;
  348. int dummyitem;
  349. bool dragging;
  350. };
  351. /*
  352. * This structure is passed to event handler functions as the `dlg'
  353. * parameter, and hence is passed back to winctrls access functions.
  354. */
  355. struct dlgparam {
  356. HWND hwnd; /* the hwnd of the dialog box */
  357. struct winctrls *controltrees[8]; /* can have several of these */
  358. int nctrltrees;
  359. char *wintitle; /* title of actual window */
  360. char *errtitle; /* title of error sub-messageboxes */
  361. void *data; /* data to pass in refresh events */
  362. union control *focused, *lastfocused; /* which ctrl has focus now/before */
  363. bool shortcuts[128]; /* track which shortcuts in use */
  364. bool coloursel_wanted; /* has an event handler asked for
  365. * a colour selector? */
  366. struct {
  367. unsigned char r, g, b; /* 0-255 */
  368. bool ok;
  369. } coloursel_result;
  370. tree234 *privdata; /* stores per-control private data */
  371. bool ended; /* has the dialog been ended? */
  372. int endresult; /* and if so, what was the result? */
  373. bool fixed_pitch_fonts; /* are we constrained to fixed fonts? */
  374. };
  375. /*
  376. * Exports from winctrls.c.
  377. */
  378. void ctlposinit(struct ctlpos *cp, HWND hwnd,
  379. int leftborder, int rightborder, int topborder);
  380. HWND doctl(struct ctlpos *cp, RECT r,
  381. char *wclass, int wstyle, int exstyle, char *wtext, int wid);
  382. void bartitle(struct ctlpos *cp, char *name, int id);
  383. void beginbox(struct ctlpos *cp, char *name, int idbox);
  384. void endbox(struct ctlpos *cp);
  385. void editboxfw(struct ctlpos *cp, bool password, char *text,
  386. int staticid, int editid);
  387. void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
  388. void bareradioline(struct ctlpos *cp, int nacross, ...);
  389. void radiobig(struct ctlpos *cp, char *text, int id, ...);
  390. void checkbox(struct ctlpos *cp, char *text, int id);
  391. void statictext(struct ctlpos *cp, char *text, int lines, int id);
  392. void staticbtn(struct ctlpos *cp, char *stext, int sid,
  393. char *btext, int bid);
  394. void static2btn(struct ctlpos *cp, char *stext, int sid,
  395. char *btext1, int bid1, char *btext2, int bid2);
  396. void staticedit(struct ctlpos *cp, char *stext,
  397. int sid, int eid, int percentedit);
  398. void staticddl(struct ctlpos *cp, char *stext,
  399. int sid, int lid, int percentlist);
  400. void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
  401. void staticpassedit(struct ctlpos *cp, char *stext,
  402. int sid, int eid, int percentedit);
  403. void bigeditctrl(struct ctlpos *cp, char *stext,
  404. int sid, int eid, int lines);
  405. void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
  406. void editbutton(struct ctlpos *cp, char *stext, int sid,
  407. int eid, char *btext, int bid);
  408. void sesssaver(struct ctlpos *cp, char *text,
  409. int staticid, int editid, int listid, ...);
  410. void envsetter(struct ctlpos *cp, char *stext, int sid,
  411. char *e1stext, int e1sid, int e1id,
  412. char *e2stext, int e2sid, int e2id,
  413. int listid, char *b1text, int b1id, char *b2text, int b2id);
  414. void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
  415. char *btext, int bid, int eid, char *s2text, int s2id);
  416. void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
  417. char *btext, int bid, ...);
  418. void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
  419. char *stext, int sid, int listid, int upbid, int dnbid);
  420. int handle_prefslist(struct prefslist *hdl,
  421. int *array, int maxmemb,
  422. bool is_dlmsg, HWND hwnd,
  423. WPARAM wParam, LPARAM lParam);
  424. void progressbar(struct ctlpos *cp, int id);
  425. void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
  426. char *e1stext, int e1sid, int e1id,
  427. char *e2stext, int e2sid, int e2id,
  428. char *btext, int bid,
  429. char *r1text, int r1id, char *r2text, int r2id);
  430. void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
  431. bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
  432. void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag);
  433. #define MAX_SHORTCUTS_PER_CTRL 16
  434. /*
  435. * This structure is what's stored for each `union control' in the
  436. * portable-dialog interface.
  437. */
  438. struct winctrl {
  439. union control *ctrl;
  440. /*
  441. * The control may have several components at the Windows
  442. * level, with different dialog IDs. To avoid needing N
  443. * separate platformsidectrl structures (which could be stored
  444. * separately in a tree234 so that lookup by ID worked), we
  445. * impose the constraint that those IDs must be in a contiguous
  446. * block.
  447. */
  448. int base_id;
  449. int num_ids;
  450. /*
  451. * For vertical alignment, the id of a particular representative
  452. * control that has the y-extent of the sensible part of the
  453. * control.
  454. */
  455. int align_id;
  456. /*
  457. * Remember what keyboard shortcuts were used by this control,
  458. * so that when we remove it again we can take them out of the
  459. * list in the dlgparam.
  460. */
  461. char shortcuts[MAX_SHORTCUTS_PER_CTRL];
  462. /*
  463. * Some controls need a piece of allocated memory in which to
  464. * store temporary data about the control.
  465. */
  466. void *data;
  467. };
  468. /*
  469. * And this structure holds a set of the above, in two separate
  470. * tree234s so that it can find an item by `union control' or by
  471. * dialog ID.
  472. */
  473. struct winctrls {
  474. tree234 *byctrl, *byid;
  475. };
  476. struct controlset;
  477. struct controlbox;
  478. void winctrl_init(struct winctrls *);
  479. void winctrl_cleanup(struct winctrls *);
  480. void winctrl_add(struct winctrls *, struct winctrl *);
  481. void winctrl_remove(struct winctrls *, struct winctrl *);
  482. struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
  483. struct winctrl *winctrl_findbyid(struct winctrls *, int);
  484. struct winctrl *winctrl_findbyindex(struct winctrls *, int);
  485. void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
  486. struct ctlpos *cp, struct controlset *s, int *id);
  487. bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
  488. WPARAM wParam, LPARAM lParam);
  489. void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
  490. bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
  491. void dp_init(struct dlgparam *dp);
  492. void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
  493. void dp_cleanup(struct dlgparam *dp);
  494. /*
  495. * Exports from wincfg.c.
  496. */
  497. void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
  498. bool midsession, int protocol);
  499. /*
  500. * Exports from windlg.c.
  501. */
  502. void defuse_showwindow(void);
  503. bool do_config(Conf *);
  504. bool do_reconfig(HWND, Conf *, int);
  505. void showeventlog(HWND);
  506. void showabout(HWND);
  507. void force_normal(HWND hwnd);
  508. void modal_about_box(HWND hwnd);
  509. void show_help(HWND hwnd);
  510. HWND event_log_window(void);
  511. /*
  512. * Exports from winmisc.c.
  513. */
  514. extern DWORD osMajorVersion, osMinorVersion, osPlatformId;
  515. void init_winver(void);
  516. void dll_hijacking_protection(void);
  517. HMODULE load_system32_dll(const char *libname);
  518. const char *win_strerror(int error);
  519. void restrict_process_acl(void);
  520. bool restricted_acl(void);
  521. void escape_registry_key(const char *in, strbuf *out);
  522. void unescape_registry_key(const char *in, strbuf *out);
  523. bool is_console_handle(HANDLE);
  524. /* A few pieces of up-to-date Windows API definition needed for older
  525. * compilers. */
  526. #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
  527. #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
  528. #endif
  529. #ifndef LOAD_LIBRARY_SEARCH_USER_DIRS
  530. #define LOAD_LIBRARY_SEARCH_USER_DIRS 0x00000400
  531. #endif
  532. #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
  533. #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100
  534. #endif
  535. #ifndef DLL_DIRECTORY_COOKIE
  536. typedef PVOID DLL_DIRECTORY_COOKIE;
  537. DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory);
  538. #endif
  539. /*
  540. * Exports from sizetip.c.
  541. */
  542. void UpdateSizeTip(HWND src, int cx, int cy);
  543. void EnableSizeTip(bool bEnable);
  544. /*
  545. * Exports from unicode.c.
  546. */
  547. struct unicode_data;
  548. void init_ucs(Conf *, struct unicode_data *);
  549. /*
  550. * Exports from winhandl.c.
  551. */
  552. #define HANDLE_FLAG_OVERLAPPED 1
  553. #define HANDLE_FLAG_IGNOREEOF 2
  554. #define HANDLE_FLAG_UNITBUFFER 4
  555. struct handle;
  556. typedef size_t (*handle_inputfn_t)(
  557. struct handle *h, const void *data, size_t len, int err);
  558. typedef void (*handle_outputfn_t)(
  559. struct handle *h, size_t new_backlog, int err);
  560. struct handle *handle_input_new(tree234 * handles_by_evtomain, HANDLE handle, handle_inputfn_t gotdata, // WINSCP
  561. void *privdata, int flags);
  562. struct handle *handle_output_new(tree234 * handles_by_evtomain, HANDLE handle, handle_outputfn_t sentdata, // WINSCP
  563. void *privdata, int flags);
  564. size_t handle_write(struct handle *h, const void *data, size_t len);
  565. void handle_write_eof(struct handle *h);
  566. HANDLE *handle_get_events(tree234 * handles_by_evtomain, int *nevents); // WINSCP
  567. void handle_free(tree234 * handles_by_evtomain, struct handle *h); // WINSCP
  568. int handle_got_event(tree234 * handles_by_evtomain, HANDLE event); // WINSCP
  569. void handle_unthrottle(struct handle *h, size_t backlog);
  570. size_t handle_backlog(struct handle *h);
  571. void *handle_get_privdata(struct handle *h);
  572. struct handle *handle_add_foreign_event(HANDLE event,
  573. void (*callback)(void *), void *ctx);
  574. /* Analogue of stdio_sink in marshal.h, for a Windows handle */
  575. struct handle_sink {
  576. struct handle *h;
  577. BinarySink_IMPLEMENTATION;
  578. };
  579. void handle_sink_init(handle_sink *sink, struct handle *h);
  580. /*
  581. * Exports from winpgntc.c.
  582. */
  583. char *agent_named_pipe_name(void);
  584. /*
  585. * Exports from winser.c.
  586. */
  587. extern const struct BackendVtable serial_backend;
  588. /*
  589. * Exports from winjump.c.
  590. */
  591. #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
  592. void add_session_to_jumplist(const char * const sessionname);
  593. void remove_session_from_jumplist(const char * const sessionname);
  594. void clear_jumplist(void);
  595. bool set_explicit_app_user_model_id(void);
  596. /*
  597. * Exports from winnoise.c.
  598. */
  599. bool win_read_random(void *buf, unsigned wanted); /* returns true on success */
  600. /*
  601. * Extra functions in winstore.c over and above the interface in
  602. * storage.h.
  603. *
  604. * These functions manipulate the Registry section which mirrors the
  605. * current Windows 7 jump list. (Because the real jump list storage is
  606. * write-only, we need to keep another copy of whatever we put in it,
  607. * so that we can put in a slightly modified version the next time.)
  608. */
  609. /* Adds a saved session to the registry jump list mirror. 'item' is a
  610. * string naming a saved session. */
  611. int add_to_jumplist_registry(const char *item);
  612. /* Removes an item from the registry jump list mirror. */
  613. int remove_from_jumplist_registry(const char *item);
  614. /* Returns the current jump list entries from the registry. Caller
  615. * must free the returned pointer, which points to a contiguous
  616. * sequence of NUL-terminated strings in memory, terminated with an
  617. * empty one. */
  618. char *get_jumplist_registry_entries(void);
  619. /*
  620. * Windows clipboard-UI wording.
  621. */
  622. #define CLIPNAME_IMPLICIT "Last selected text"
  623. #define CLIPNAME_EXPLICIT "System clipboard"
  624. #define CLIPNAME_EXPLICIT_OBJECT "system clipboard"
  625. /* These defaults are the ones PuTTY has historically had */
  626. #define CLIPUI_DEFAULT_AUTOCOPY true
  627. #define CLIPUI_DEFAULT_MOUSE CLIPUI_EXPLICIT
  628. #define CLIPUI_DEFAULT_INS CLIPUI_EXPLICIT
  629. /* In winmisc.c */
  630. char *registry_get_string(HKEY root, const char *path, const char *leaf);
  631. /* In wincliloop.c */
  632. typedef bool (*cliloop_pre_t)(void *vctx, const HANDLE **extra_handles,
  633. size_t *n_extra_handles);
  634. typedef bool (*cliloop_post_t)(void *vctx, size_t extra_handle_index);
  635. void cli_main_loop(cliloop_pre_t pre, cliloop_post_t post, void *ctx);
  636. bool cliloop_null_pre(void *vctx, const HANDLE **, size_t *);
  637. bool cliloop_null_post(void *vctx, size_t);
  638. #endif