winstuff.h 24 KB

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