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
30 #define BUILDINFO_PLATFORM "Windows"
35 #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
43 struct FontSpec *fontspec_new(const char *name,
44 int bold, int height, int charset);
46 #ifndef CLEARTYPE_QUALITY
47 #define CLEARTYPE_QUALITY 5
49 #define FONT_QUALITY(fq) ( \
50 (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
51 (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
52 (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
55 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
56 * wchar_t strings with environment */
59 * Where we can, we use GetWindowLongPtr and friends because they're
60 * more useful on 64-bit platforms, but they're a relatively recent
61 * innovation, missing from VC++ 6 and older MinGW. Degrade nicely.
62 * (NB that on some systems, some of these things are available but
67 /* GetClassLongPtr and friends */
68 #undef GetClassLongPtr
69 #define GetClassLongPtr GetClassLong
70 #undef SetClassLongPtr
71 #define SetClassLongPtr SetClassLong
72 #define GCLP_HCURSOR GCL_HCURSOR
73 /* GetWindowLongPtr and friends */
74 #undef GetWindowLongPtr
75 #define GetWindowLongPtr GetWindowLong
76 #undef SetWindowLongPtr
77 #define SetWindowLongPtr SetWindowLong
79 #define GWLP_USERDATA GWL_USERDATA
81 #define DWLP_MSGRESULT DWL_MSGRESULT
82 /* Since we've clobbered the above functions, we should clobber the
83 * associated type regardless of whether it's defined. */
88 #define BOXFLAGS DLGWINDOWEXTRA
89 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
93 #define NO_SECUREZEROMEMORY /* winelib doesn't have this */
96 #ifndef NO_SECUREZEROMEMORY
97 #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
101 /* Up-to-date Windows headers warn that the unprefixed versions of
102 * these names are deprecated. */
103 #define stricmp _stricmp
104 #define strnicmp _strnicmp
106 /* Compiling with winegcc, _neither_ version of these functions
107 * exists. Use the POSIX names. */
108 #define stricmp strcasecmp
109 #define strnicmp strncasecmp
112 #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE /* used in sshshare.c */
115 * Dynamically linked functions. These come in two flavours:
117 * - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
118 * so will always dynamically link against exactly what is specified
119 * in "name". If you're not sure, use this one.
121 * - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
122 * preprocessor definitions like "#define foo bar"; this is principally
123 * intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
124 * If your function has an argument of type "LPTSTR" or similar, this
125 * is the variant to use.
126 * (However, it can't always be used, as it trips over more complicated
127 * macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
129 * (DECL_WINDOWS_FUNCTION works with both these variants.)
131 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
132 typedef rettype (WINAPI *t_##name) params; \
133 linkage t_##name p_##name
135 #define STR(x) STR1(x)
136 #define GET_WINDOWS_FUNCTION_PP(module, name) \
137 (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
138 #define GET_WINDOWS_FUNCTION(module, name) \
139 (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
142 * Global variables. Most modules declare these `extern', but
143 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
144 * module, and so will get them properly defined.
147 #ifdef PUTTY_DO_GLOBALS
150 #define GLOBAL extern
154 #ifndef DONE_TYPEDEFS
155 #define DONE_TYPEDEFS
156 typedef struct conf_tag Conf;
157 typedef struct backend_tag Backend;
158 typedef struct terminal_tag Terminal;
161 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
162 #define PUTTY_REG_PARENT "Software\\SimonTatham"
163 #define PUTTY_REG_PARENT_CHILD "PuTTY"
164 #define PUTTY_REG_GPARENT "Software"
165 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
167 /* Result values for the jumplist registry functions. */
168 #define JUMPLISTREG_OK 0
169 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
170 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
171 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
172 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
173 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
175 #define PUTTY_HELP_FILE "putty.hlp"
176 #define PUTTY_CHM_FILE "putty.chm"
177 #define PUTTY_HELP_CONTENTS "putty.cnt"
179 #define GETTICKCOUNT GetTickCount
180 #define CURSORBLINK GetCaretBlinkTime()
181 #define TICKSPERSEC 1000 /* GetTickCount returns milliseconds */
183 #define DEFAULT_CODEPAGE CP_ACP
184 #define USES_VTLINE_HACK
188 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
189 #define PUTTY_UINT32_DEFINED
195 #define GSS_CC CALLBACK
197 typedef struct Ssh_gss_buf {
202 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
203 typedef void *Ssh_gss_name;
208 * Window handles for the windows that can be running during a
211 GLOBAL HWND hwnd; /* the main terminal window */
215 * The all-important instance handle.
217 GLOBAL HINSTANCE hinst;
220 * Help file stuff in winhelp.c.
222 void init_help(void);
223 void shutdown_help(void);
225 void launch_help(HWND hwnd, const char *topic);
226 void quit_help(HWND hwnd);
229 * The terminal and logging context are notionally local to the
230 * Windows front end, but they must be shared between window.c and
231 * windlg.c. Likewise the saved-sessions list.
233 GLOBAL Terminal *term;
236 #define WM_NETEVENT (WM_APP + 5)
239 * On Windows, we send MA_2CLK as the only event marking the second
240 * press of a mouse button. Compare unix.h.
242 #define MULTICLICK_ONLY_EVENT 1
245 * On Windows, data written to the clipboard must be NUL-terminated.
247 #define SELECTION_NUL_TERMINATED 1
250 * On Windows, copying to the clipboard terminates lines with CRLF.
252 #define SEL_NL { 13, 10 }
255 * sk_getxdmdata() does not exist under Windows (not that I
256 * couldn't write it if I wanted to, but I haven't bothered), so
257 * it's a macro which always returns NULL. With any luck this will
258 * cause the compiler to notice it can optimise away the
259 * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
261 #define sk_getxdmdata(socket, lenp) (NULL)
264 * File-selector filter strings used in the config box. On Windows,
265 * these strings are of exactly the type needed to go in
266 * `lpstrFilter' in an OPENFILENAME structure.
268 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
269 "All Files (*.*)\0*\0\0\0")
270 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
271 "All Files (*.*)\0*\0\0\0")
272 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
273 "All Files (*.*)\0*\0\0\0")
276 * Exports from winnet.c.
278 extern int select_result(WPARAM, LPARAM);
281 * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
282 * what it can get, which means any WinSock routines used outside
283 * that module must be exported from it as function pointers. So
286 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
287 (SOCKET, HWND, u_int, long));
288 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
289 (SOCKET, WSAEVENT, long));
290 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
291 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
292 (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
293 #ifdef NEED_DECLARATION_OF_SELECT
294 /* This declaration is protected by an ifdef for the sake of building
295 * against winelib, in which you have to include winsock2.h before
296 * stdlib.h so that the right fd_set type gets defined. It would be a
297 * pain to do that throughout this codebase, so instead I arrange that
298 * only a modules actually needing to use (or define, or initialise)
299 * this function pointer will see its declaration, and _those_ modules
300 * - which will be Windows-specific anyway - can take more care. */
301 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
302 (int, fd_set FAR *, fd_set FAR *,
303 fd_set FAR *, const struct timeval FAR *));
306 extern int socket_writable(SOCKET skt);
308 extern void socket_reselect_all(void);
311 * Exports from winctrls.c.
320 int boxystart, boxid;
325 * Exports from winutils.c.
327 typedef struct filereq_tag filereq; /* cwd for file requester */
328 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
329 filereq *filereq_new(void);
330 void filereq_free(filereq *state);
331 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
332 char *GetDlgItemText_alloc(HWND hwnd, int id);
333 void split_into_argv(char *, int *, char ***, char ***);
336 * Private structure for prefslist state. Only in the header file
337 * so that we can delegate allocation to callers.
340 int listid, upbid, dnbid;
347 * This structure is passed to event handler functions as the `dlg'
348 * parameter, and hence is passed back to winctrls access functions.
351 HWND hwnd; /* the hwnd of the dialog box */
352 struct winctrls *controltrees[8]; /* can have several of these */
354 char *wintitle; /* title of actual window */
355 char *errtitle; /* title of error sub-messageboxes */
356 void *data; /* data to pass in refresh events */
357 union control *focused, *lastfocused; /* which ctrl has focus now/before */
358 char shortcuts[128]; /* track which shortcuts in use */
359 int coloursel_wanted; /* has an event handler asked for
360 * a colour selector? */
361 struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
362 tree234 *privdata; /* stores per-control private data */
363 int ended, endresult; /* has the dialog been ended? */
364 int fixed_pitch_fonts; /* are we constrained to fixed fonts? */
368 * Exports from winctrls.c.
370 void ctlposinit(struct ctlpos *cp, HWND hwnd,
371 int leftborder, int rightborder, int topborder);
372 HWND doctl(struct ctlpos *cp, RECT r,
373 char *wclass, int wstyle, int exstyle, char *wtext, int wid);
374 void bartitle(struct ctlpos *cp, char *name, int id);
375 void beginbox(struct ctlpos *cp, char *name, int idbox);
376 void endbox(struct ctlpos *cp);
377 void editboxfw(struct ctlpos *cp, int password, char *text,
378 int staticid, int editid);
379 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
380 void bareradioline(struct ctlpos *cp, int nacross, ...);
381 void radiobig(struct ctlpos *cp, char *text, int id, ...);
382 void checkbox(struct ctlpos *cp, char *text, int id);
383 void statictext(struct ctlpos *cp, char *text, int lines, int id);
384 void staticbtn(struct ctlpos *cp, char *stext, int sid,
385 char *btext, int bid);
386 void static2btn(struct ctlpos *cp, char *stext, int sid,
387 char *btext1, int bid1, char *btext2, int bid2);
388 void staticedit(struct ctlpos *cp, char *stext,
389 int sid, int eid, int percentedit);
390 void staticddl(struct ctlpos *cp, char *stext,
391 int sid, int lid, int percentlist);
392 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
393 void staticpassedit(struct ctlpos *cp, char *stext,
394 int sid, int eid, int percentedit);
395 void bigeditctrl(struct ctlpos *cp, char *stext,
396 int sid, int eid, int lines);
397 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
398 void editbutton(struct ctlpos *cp, char *stext, int sid,
399 int eid, char *btext, int bid);
400 void sesssaver(struct ctlpos *cp, char *text,
401 int staticid, int editid, int listid, ...);
402 void envsetter(struct ctlpos *cp, char *stext, int sid,
403 char *e1stext, int e1sid, int e1id,
404 char *e2stext, int e2sid, int e2id,
405 int listid, char *b1text, int b1id, char *b2text, int b2id);
406 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
407 char *btext, int bid, int eid, char *s2text, int s2id);
408 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
409 char *btext, int bid, ...);
410 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
411 char *stext, int sid, int listid, int upbid, int dnbid);
412 int handle_prefslist(struct prefslist *hdl,
413 int *array, int maxmemb,
414 int is_dlmsg, HWND hwnd,
415 WPARAM wParam, LPARAM lParam);
416 void progressbar(struct ctlpos *cp, int id);
417 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
418 char *e1stext, int e1sid, int e1id,
419 char *e2stext, int e2sid, int e2id,
420 char *btext, int bid,
421 char *r1text, int r1id, char *r2text, int r2id);
423 void dlg_auto_set_fixed_pitch_flag(void *dlg);
424 int dlg_get_fixed_pitch_flag(void *dlg);
425 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
427 #define MAX_SHORTCUTS_PER_CTRL 16
430 * This structure is what's stored for each `union control' in the
431 * portable-dialog interface.
436 * The control may have several components at the Windows
437 * level, with different dialog IDs. To avoid needing N
438 * separate platformsidectrl structures (which could be stored
439 * separately in a tree234 so that lookup by ID worked), we
440 * impose the constraint that those IDs must be in a contiguous
446 * Remember what keyboard shortcuts were used by this control,
447 * so that when we remove it again we can take them out of the
448 * list in the dlgparam.
450 char shortcuts[MAX_SHORTCUTS_PER_CTRL];
452 * Some controls need a piece of allocated memory in which to
453 * store temporary data about the control.
458 * And this structure holds a set of the above, in two separate
459 * tree234s so that it can find an item by `union control' or by
463 tree234 *byctrl, *byid;
468 void winctrl_init(struct winctrls *);
469 void winctrl_cleanup(struct winctrls *);
470 void winctrl_add(struct winctrls *, struct winctrl *);
471 void winctrl_remove(struct winctrls *, struct winctrl *);
472 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
473 struct winctrl *winctrl_findbyid(struct winctrls *, int);
474 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
475 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
476 struct ctlpos *cp, struct controlset *s, int *id);
477 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
478 WPARAM wParam, LPARAM lParam);
479 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
480 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
482 void dp_init(struct dlgparam *dp);
483 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
484 void dp_cleanup(struct dlgparam *dp);
487 * Exports from wincfg.c.
489 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
490 int midsession, int protocol);
493 * Exports from windlg.c.
495 void defuse_showwindow(void);
497 int do_reconfig(HWND, int);
498 void showeventlog(HWND);
499 void showabout(HWND);
500 void force_normal(HWND hwnd);
501 void modal_about_box(HWND hwnd);
502 void show_help(HWND hwnd);
505 * Exports from winmisc.c.
507 extern OSVERSIONINFO osVersion;
508 void dll_hijacking_protection(void);
509 BOOL init_winver(void);
510 HMODULE load_system32_dll(const char *libname);
511 const char *win_strerror(int error);
512 void restrict_process_acl(void);
513 GLOBAL int restricted_acl;
516 * Exports from sizetip.c.
518 void UpdateSizeTip(HWND src, int cx, int cy);
519 void EnableSizeTip(int bEnable);
522 * Exports from unicode.c.
525 void init_ucs(Conf *, struct unicode_data *);
528 * Exports from winhandl.c.
530 #define HANDLE_FLAG_OVERLAPPED 1
531 #define HANDLE_FLAG_IGNOREEOF 2
532 #define HANDLE_FLAG_UNITBUFFER 4
534 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
535 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
536 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
537 void *privdata, int flags);
538 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
539 void *privdata, int flags);
540 int handle_write(struct handle *h, const void *data, int len);
541 void handle_write_eof(struct handle *h);
542 HANDLE *handle_get_events(int *nevents);
543 void handle_free(struct handle *h);
544 void handle_got_event(HANDLE event);
545 void handle_unthrottle(struct handle *h, int backlog);
546 int handle_backlog(struct handle *h);
547 void *handle_get_privdata(struct handle *h);
548 struct handle *handle_add_foreign_event(HANDLE event,
549 void (*callback)(void *), void *ctx);
552 * winpgntc.c needs to schedule callbacks for asynchronous agent
553 * requests. This has to be done differently in GUI and console, so
554 * there's an exported function used for the purpose.
556 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
557 * synchronous in pscp and psftp.
559 void agent_schedule_callback(void (*callback)(void *, void *, int),
560 void *callback_ctx, void *data, int len);
561 #define FLAG_SYNCAGENT 0x1000
564 * Exports from winser.c.
566 extern Backend serial_backend;
569 * Exports from winjump.c.
571 #define JUMPLIST_SUPPORTED /* suppress #defines in putty.h */
572 void add_session_to_jumplist(const char * const sessionname);
573 void remove_session_from_jumplist(const char * const sessionname);
574 void clear_jumplist(void);
575 BOOL set_explicit_app_user_model_id();
578 * Extra functions in winstore.c over and above the interface in
581 * These functions manipulate the Registry section which mirrors the
582 * current Windows 7 jump list. (Because the real jump list storage is
583 * write-only, we need to keep another copy of whatever we put in it,
584 * so that we can put in a slightly modified version the next time.)
587 /* Adds a saved session to the registry jump list mirror. 'item' is a
588 * string naming a saved session. */
589 int add_to_jumplist_registry(const char *item);
591 /* Removes an item from the registry jump list mirror. */
592 int remove_from_jumplist_registry(const char *item);
594 /* Returns the current jump list entries from the registry. Caller
595 * must free the returned pointer, which points to a contiguous
596 * sequence of NUL-terminated strings in memory, terminated with an
598 char *get_jumplist_registry_entries(void);