2 * winstuff.h: Windows-specific inter-module stuff.
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
12 #include <stdio.h> /* for FILENAME_MAX */
14 /* We use uintptr_t for Win32/Win64 portability, so we should in
15 * principle include stdint.h, which defines it according to the C
16 * standard. But older versions of Visual Studio - including the one
17 * used for official PuTTY builds as of 2015-09-28 - don't provide
18 * stdint.h at all, but do (non-standardly) define uintptr_t in
19 * stddef.h. So here we try to make sure _some_ standard header is
20 * included which defines uintptr_t. */
22 #if !defined _MSC_VER || _MSC_VER >= 1600
33 #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
41 struct FontSpec *fontspec_new(const char *name,
42 int bold, int height, int charset);
44 #ifndef CLEARTYPE_QUALITY
45 #define CLEARTYPE_QUALITY 5
47 #define FONT_QUALITY(fq) ( \
48 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
49 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
50 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
53 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
54 * wchar_t strings with environment */
57 * Where we can, we use GetWindowLongPtr and friends because they're
58 * more useful on 64-bit platforms, but they're a relatively recent
59 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
60 * (NB that on some systems, some of these things are available but
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
77 #define GWLP_USERDATA GWL_USERDATA
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. */
86 #define BOXFLAGS DLGWINDOWEXTRA
87 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
90 #ifndef NO_SECUREZEROMEMORY
91 #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
94 #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in sshshare.c */
97 * Dynamically linked functions. These come in two flavours:
99 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
100 * so will always dynamically link against exactly what is specified
101 * in "name". If you're not sure, use this one.
103 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
104 * preprocessor definitions like "#define foo bar"; this is principally
105 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
106 * If your function has an argument of type "LPTSTR" or similar, this
107 * is the variant to use.
108 * (However, it can't always be used, as it trips over more complicated
109 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
111 * (DECL_WINDOWS_FUNCTION works with both these variants.)
113 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
114 typedef rettype (WINAPI *t_##name) params; \
115 linkage t_##name p_##name
117 #define STR(x) STR1(x)
118 #define GET_WINDOWS_FUNCTION_PP(module, name) \
119 (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
120 #define GET_WINDOWS_FUNCTION(module, name) \
121 (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
124 * Global variables. Most modules declare these `extern', but
125 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
126 * module, and so will get them properly defined.
129 #ifdef PUTTY_DO_GLOBALS
132 #define GLOBAL extern
136 #ifndef DONE_TYPEDEFS
137 #define DONE_TYPEDEFS
138 typedef struct conf_tag Conf;
139 typedef struct backend_tag Backend;
140 typedef struct terminal_tag Terminal;
143 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
144 #define PUTTY_REG_PARENT "Software\\SimonTatham"
145 #define PUTTY_REG_PARENT_CHILD "PuTTY"
146 #define PUTTY_REG_GPARENT "Software"
147 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
149 /* Result values for the jumplist registry functions. */
150 #define JUMPLISTREG_OK 0
151 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
152 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
153 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
154 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
155 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
157 #define PUTTY_HELP_FILE "putty.hlp"
158 #define PUTTY_CHM_FILE "putty.chm"
159 #define PUTTY_HELP_CONTENTS "putty.cnt"
161 #define GETTICKCOUNT GetTickCount
162 #define CURSORBLINK GetCaretBlinkTime()
163 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
165 #define DEFAULT_CODEPAGE CP_ACP
166 #define USES_VTLINE_HACK
170 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
171 #define PUTTY_UINT32_DEFINED
177 #define GSS_CC CALLBACK
179 typedef struct Ssh_gss_buf {
184 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
185 typedef void *Ssh_gss_name;
190 * Window handles for the windows that can be running during a
193 GLOBAL HWND hwnd; /* the main terminal window */
197 * The all-important instance handle.
199 GLOBAL HINSTANCE hinst;
202 * Help file stuff in winhelp.c.
204 void init_help(void);
205 void shutdown_help(void);
207 void launch_help(HWND hwnd, const char *topic);
208 void quit_help(HWND hwnd);
211 * The terminal and logging context are notionally local to the
212 * Windows front end, but they must be shared between window.c and
213 * windlg.c. Likewise the saved-sessions list.
215 GLOBAL Terminal *term;
218 #define WM_NETEVENT (WM_APP + 5)
221 * On Windows, we send MA_2CLK as the only event marking the second
222 * press of a mouse button. Compare unix.h.
224 #define MULTICLICK_ONLY_EVENT 1
227 * On Windows, data written to the clipboard must be NUL-terminated.
229 #define SELECTION_NUL_TERMINATED 1
232 * On Windows, copying to the clipboard terminates lines with CRLF.
234 #define SEL_NL { 13, 10 }
237 * sk_getxdmdata() does not exist under Windows (not that I
238 * couldn't write it if I wanted to, but I haven't bothered), so
239 * it's a macro which always returns NULL. With any luck this will
240 * cause the compiler to notice it can optimise away the
241 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
243 #define sk_getxdmdata(socket, lenp) (NULL)
246 * File-selector filter strings used in the config box. On Windows,
247 * these strings are of exactly the type needed to go in
248 * `lpstrFilter' in an OPENFILENAME structure.
250 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
251 "All Files (*.*)\0*\0\0\0")
252 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
253 "All Files (*.*)\0*\0\0\0")
254 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
255 "All Files (*.*)\0*\0\0\0")
258 * Exports from winnet.c.
260 extern int select_result(WPARAM, LPARAM);
263 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
264 * what it can get, which means any WinSock routines used outside
265 * that module must be exported from it as function pointers. So
268 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
269 (SOCKET, HWND, u_int, long));
270 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
271 (SOCKET, WSAEVENT, long));
272 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
273 (int, fd_set FAR *, fd_set FAR *,
274 fd_set FAR *, const struct timeval FAR *));
275 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
276 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
277 (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
279 extern int socket_writable(SOCKET skt);
281 extern void socket_reselect_all(void);
284 * Exports from winctrls.c.
293 int boxystart, boxid;
298 * Exports from winutils.c.
300 typedef struct filereq_tag filereq; /* cwd for file requester */
301 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
302 filereq *filereq_new(void);
303 void filereq_free(filereq *state);
304 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
305 char *GetDlgItemText_alloc(HWND hwnd, int id);
306 void split_into_argv(char *, int *, char ***, char ***);
309 * Private structure for prefslist state. Only in the header file
310 * so that we can delegate allocation to callers.
313 int listid, upbid, dnbid;
320 * This structure is passed to event handler functions as the `dlg'
321 * parameter, and hence is passed back to winctrls access functions.
324 HWND hwnd; /* the hwnd of the dialog box */
325 struct winctrls *controltrees[8]; /* can have several of these */
327 char *wintitle; /* title of actual window */
328 char *errtitle; /* title of error sub-messageboxes */
329 void *data; /* data to pass in refresh events */
330 union control *focused, *lastfocused; /* which ctrl has focus now/before */
331 char shortcuts[128]; /* track which shortcuts in use */
332 int coloursel_wanted; /* has an event handler asked for
333 * a colour selector? */
334 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
335 tree234 *privdata; /* stores per-control private data */
336 int ended, endresult; /* has the dialog been ended? */
337 int fixed_pitch_fonts; /* are we constrained to fixed fonts? */
341 * Exports from winctrls.c.
343 void ctlposinit(struct ctlpos *cp, HWND hwnd,
344 int leftborder, int rightborder, int topborder);
345 HWND doctl(struct ctlpos *cp, RECT r,
346 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
347 void bartitle(struct ctlpos *cp, char *name, int id);
348 void beginbox(struct ctlpos *cp, char *name, int idbox);
349 void endbox(struct ctlpos *cp);
350 void editboxfw(struct ctlpos *cp, int password, char *text,
351 int staticid, int editid);
352 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
353 void bareradioline(struct ctlpos *cp, int nacross, ...);
354 void radiobig(struct ctlpos *cp, char *text, int id, ...);
355 void checkbox(struct ctlpos *cp, char *text, int id);
356 void statictext(struct ctlpos *cp, char *text, int lines, int id);
357 void staticbtn(struct ctlpos *cp, char *stext, int sid,
358 char *btext, int bid);
359 void static2btn(struct ctlpos *cp, char *stext, int sid,
360 char *btext1, int bid1, char *btext2, int bid2);
361 void staticedit(struct ctlpos *cp, char *stext,
362 int sid, int eid, int percentedit);
363 void staticddl(struct ctlpos *cp, char *stext,
364 int sid, int lid, int percentlist);
365 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
366 void staticpassedit(struct ctlpos *cp, char *stext,
367 int sid, int eid, int percentedit);
368 void bigeditctrl(struct ctlpos *cp, char *stext,
369 int sid, int eid, int lines);
370 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
371 void editbutton(struct ctlpos *cp, char *stext, int sid,
372 int eid, char *btext, int bid);
373 void sesssaver(struct ctlpos *cp, char *text,
374 int staticid, int editid, int listid, ...);
375 void envsetter(struct ctlpos *cp, char *stext, int sid,
376 char *e1stext, int e1sid, int e1id,
377 char *e2stext, int e2sid, int e2id,
378 int listid, char *b1text, int b1id, char *b2text, int b2id);
379 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
380 char *btext, int bid, int eid, char *s2text, int s2id);
381 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
382 char *btext, int bid, ...);
383 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
384 char *stext, int sid, int listid, int upbid, int dnbid);
385 int handle_prefslist(struct prefslist *hdl,
386 int *array, int maxmemb,
387 int is_dlmsg, HWND hwnd,
388 WPARAM wParam, LPARAM lParam);
389 void progressbar(struct ctlpos *cp, int id);
390 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
391 char *e1stext, int e1sid, int e1id,
392 char *e2stext, int e2sid, int e2id,
393 char *btext, int bid,
394 char *r1text, int r1id, char *r2text, int r2id);
396 void dlg_auto_set_fixed_pitch_flag(void *dlg);
397 int dlg_get_fixed_pitch_flag(void *dlg);
398 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
400 #define MAX_SHORTCUTS_PER_CTRL 16
403 * This structure is what's stored for each `union control' in the
404 * portable-dialog interface.
409 * The control may have several components at the Windows
410 * level, with different dialog IDs. To avoid needing N
411 * separate platformsidectrl structures (which could be stored
412 * separately in a tree234 so that lookup by ID worked), we
413 * impose the constraint that those IDs must be in a contiguous
419 * Remember what keyboard shortcuts were used by this control,
420 * so that when we remove it again we can take them out of the
421 * list in the dlgparam.
423 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
425 * Some controls need a piece of allocated memory in which to
426 * store temporary data about the control.
431 * And this structure holds a set of the above, in two separate
432 * tree234s so that it can find an item by `union control' or by
436 tree234 *byctrl, *byid;
441 void winctrl_init(struct winctrls *);
442 void winctrl_cleanup(struct winctrls *);
443 void winctrl_add(struct winctrls *, struct winctrl *);
444 void winctrl_remove(struct winctrls *, struct winctrl *);
445 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
446 struct winctrl *winctrl_findbyid(struct winctrls *, int);
447 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
448 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
449 struct ctlpos *cp, struct controlset *s, int *id);
450 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
451 WPARAM wParam, LPARAM lParam);
452 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
453 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
455 void dp_init(struct dlgparam *dp);
456 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
457 void dp_cleanup(struct dlgparam *dp);
460 * Exports from wincfg.c.
462 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
463 int midsession, int protocol);
466 * Exports from windlg.c.
468 void defuse_showwindow(void);
470 int do_reconfig(HWND, int);
471 void showeventlog(HWND);
472 void showabout(HWND);
473 void force_normal(HWND hwnd);
474 void modal_about_box(HWND hwnd);
475 void show_help(HWND hwnd);
478 * Exports from winmisc.c.
480 extern OSVERSIONINFO osVersion;
481 BOOL init_winver(void);
482 HMODULE load_system32_dll(const char *libname);
483 const char *win_strerror(int error);
486 * Exports from sizetip.c.
488 void UpdateSizeTip(HWND src, int cx, int cy);
489 void EnableSizeTip(int bEnable);
492 * Exports from unicode.c.
495 void init_ucs(Conf *, struct unicode_data *);
498 * Exports from winhandl.c.
500 #define HANDLE_FLAG_OVERLAPPED 1
501 #define HANDLE_FLAG_IGNOREEOF 2
502 #define HANDLE_FLAG_UNITBUFFER 4
504 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
505 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
506 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
507 void *privdata, int flags);
508 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
509 void *privdata, int flags);
510 int handle_write(struct handle *h, const void *data, int len);
511 void handle_write_eof(struct handle *h);
512 HANDLE *handle_get_events(int *nevents);
513 void handle_free(struct handle *h);
514 void handle_got_event(HANDLE event);
515 void handle_unthrottle(struct handle *h, int backlog);
516 int handle_backlog(struct handle *h);
517 void *handle_get_privdata(struct handle *h);
518 struct handle *handle_add_foreign_event(HANDLE event,
519 void (*callback)(void *), void *ctx);
522 * winpgntc.c needs to schedule callbacks for asynchronous agent
523 * requests. This has to be done differently in GUI and console, so
524 * there's an exported function used for the purpose.
526 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
527 * synchronous in pscp and psftp.
529 void agent_schedule_callback(void (*callback)(void *, void *, int),
530 void *callback_ctx, void *data, int len);
531 #define FLAG_SYNCAGENT 0x1000
534 * Exports from winser.c.
536 extern Backend serial_backend;
539 * Exports from winjump.c.
541 #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
542 void add_session_to_jumplist(const char * const sessionname);
543 void remove_session_from_jumplist(const char * const sessionname);
544 void clear_jumplist(void);
547 * Extra functions in winstore.c over and above the interface in
550 * These functions manipulate the Registry section which mirrors the
551 * current Windows 7 jump list. (Because the real jump list storage is
552 * write-only, we need to keep another copy of whatever we put in it,
553 * so that we can put in a slightly modified version the next time.)
556 /* Adds a saved session to the registry jump list mirror. 'item' is a
557 * string naming a saved session. */
558 int add_to_jumplist_registry(const char *item);
560 /* Removes an item from the registry jump list mirror. */
561 int remove_from_jumplist_registry(const char *item);
563 /* Returns the current jump list entries from the registry. Caller
564 * must free the returned pointer, which points to a contiguous
565 * sequence of NUL-terminated strings in memory, terminated with an
567 char *get_jumplist_registry_entries(void);