winstuff.h 24 KB

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