winstuff.h 25 KB

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