]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - windows/winstuff.h
Include 'build info' in all --version text and About boxes.
[PuTTY.git] / windows / winstuff.h
1 /*
2  * winstuff.h: Windows-specific inter-module stuff.
3  */
4
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
7
8 #ifndef AUTO_WINSOCK
9 #include <winsock2.h>
10 #endif
11 #include <windows.h>
12 #include <stdio.h>                     /* for FILENAME_MAX */
13
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. */
21 #include <stddef.h>
22 #if !defined _MSC_VER || _MSC_VER >= 1600
23 #include <stdint.h>
24 #endif
25
26 #include "tree234.h"
27
28 #include "winhelp.h"
29
30 #define BUILDINFO_PLATFORM "Windows"
31
32 struct Filename {
33     char *path;
34 };
35 #define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
36
37 struct FontSpec {
38     char *name;
39     int isbold;
40     int height;
41     int charset;
42 };
43 struct FontSpec *fontspec_new(const char *name,
44                                int bold, int height, int charset);
45
46 #ifndef CLEARTYPE_QUALITY
47 #define CLEARTYPE_QUALITY 5
48 #endif
49 #define FONT_QUALITY(fq) ( \
50     (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
51     (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
52     (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
53     CLEARTYPE_QUALITY)
54
55 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
56                            * wchar_t strings with environment */
57
58 /*
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
63  * not others...)
64  */
65
66 #ifndef GCLP_HCURSOR
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
78 #undef  GWLP_USERDATA
79 #define GWLP_USERDATA GWL_USERDATA
80 #undef  DWLP_MSGRESULT
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. */
84 #undef LONG_PTR
85 #define LONG_PTR LONG
86 #endif
87
88 #define BOXFLAGS DLGWINDOWEXTRA
89 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
90 #define DF_END 0x0001
91
92 #ifndef NO_SECUREZEROMEMORY
93 #define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
94 #endif
95
96 #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE   /* used in sshshare.c */
97
98 /*
99  * Dynamically linked functions. These come in two flavours:
100  *
101  *  - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
102  *    so will always dynamically link against exactly what is specified
103  *    in "name". If you're not sure, use this one.
104  *
105  *  - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
106  *    preprocessor definitions like "#define foo bar"; this is principally
107  *    intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
108  *    If your function has an argument of type "LPTSTR" or similar, this
109  *    is the variant to use.
110  *    (However, it can't always be used, as it trips over more complicated
111  *    macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
112  *
113  * (DECL_WINDOWS_FUNCTION works with both these variants.)
114  */
115 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
116     typedef rettype (WINAPI *t_##name) params; \
117     linkage t_##name p_##name
118 #define STR1(x) #x
119 #define STR(x) STR1(x)
120 #define GET_WINDOWS_FUNCTION_PP(module, name) \
121     (p_##name = module ? (t_##name) GetProcAddress(module, STR(name)) : NULL)
122 #define GET_WINDOWS_FUNCTION(module, name) \
123     (p_##name = module ? (t_##name) GetProcAddress(module, #name) : NULL)
124
125 /*
126  * Global variables. Most modules declare these `extern', but
127  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
128  * module, and so will get them properly defined.
129 */
130 #ifndef GLOBAL
131 #ifdef PUTTY_DO_GLOBALS
132 #define GLOBAL
133 #else
134 #define GLOBAL extern
135 #endif
136 #endif
137
138 #ifndef DONE_TYPEDEFS
139 #define DONE_TYPEDEFS
140 typedef struct conf_tag Conf;
141 typedef struct backend_tag Backend;
142 typedef struct terminal_tag Terminal;
143 #endif
144
145 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
146 #define PUTTY_REG_PARENT "Software\\SimonTatham"
147 #define PUTTY_REG_PARENT_CHILD "PuTTY"
148 #define PUTTY_REG_GPARENT "Software"
149 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
150
151 /* Result values for the jumplist registry functions. */
152 #define JUMPLISTREG_OK 0
153 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
154 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
155 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
156 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
157 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
158
159 #define PUTTY_HELP_FILE "putty.hlp"
160 #define PUTTY_CHM_FILE "putty.chm"
161 #define PUTTY_HELP_CONTENTS "putty.cnt"
162
163 #define GETTICKCOUNT GetTickCount
164 #define CURSORBLINK GetCaretBlinkTime()
165 #define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
166
167 #define DEFAULT_CODEPAGE CP_ACP
168 #define USES_VTLINE_HACK
169
170 typedef HDC Context;
171
172 typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
173 #define PUTTY_UINT32_DEFINED
174
175 #ifndef NO_GSSAPI
176 /*
177  * GSS-API stuff
178  */
179 #define GSS_CC CALLBACK
180 /*
181 typedef struct Ssh_gss_buf {
182     size_t length;
183     char *value;
184 } Ssh_gss_buf;
185
186 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
187 typedef void *Ssh_gss_name;
188 */
189 #endif
190
191 /*
192  * Window handles for the windows that can be running during a
193  * PuTTY session.
194  */
195 GLOBAL HWND hwnd;       /* the main terminal window */
196 GLOBAL HWND logbox;
197
198 /*
199  * The all-important instance handle.
200  */
201 GLOBAL HINSTANCE hinst;
202
203 /*
204  * Help file stuff in winhelp.c.
205  */
206 void init_help(void);
207 void shutdown_help(void);
208 int has_help(void);
209 void launch_help(HWND hwnd, const char *topic);
210 void quit_help(HWND hwnd);
211
212 /*
213  * The terminal and logging context are notionally local to the
214  * Windows front end, but they must be shared between window.c and
215  * windlg.c. Likewise the saved-sessions list.
216  */
217 GLOBAL Terminal *term;
218 GLOBAL void *logctx;
219
220 #define WM_NETEVENT  (WM_APP + 5)
221
222 /*
223  * On Windows, we send MA_2CLK as the only event marking the second
224  * press of a mouse button. Compare unix.h.
225  */
226 #define MULTICLICK_ONLY_EVENT 1
227
228 /*
229  * On Windows, data written to the clipboard must be NUL-terminated.
230  */
231 #define SELECTION_NUL_TERMINATED 1
232
233 /*
234  * On Windows, copying to the clipboard terminates lines with CRLF.
235  */
236 #define SEL_NL { 13, 10 }
237
238 /*
239  * sk_getxdmdata() does not exist under Windows (not that I
240  * couldn't write it if I wanted to, but I haven't bothered), so
241  * it's a macro which always returns NULL. With any luck this will
242  * cause the compiler to notice it can optimise away the
243  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
244  */
245 #define sk_getxdmdata(socket, lenp) (NULL)
246
247 /*
248  * File-selector filter strings used in the config box. On Windows,
249  * these strings are of exactly the type needed to go in
250  * `lpstrFilter' in an OPENFILENAME structure.
251  */
252 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
253                               "All Files (*.*)\0*\0\0\0")
254 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
255                                "All Files (*.*)\0*\0\0\0")
256 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
257                                  "All Files (*.*)\0*\0\0\0")
258
259 /*
260  * Exports from winnet.c.
261  */
262 extern int select_result(WPARAM, LPARAM);
263
264 /*
265  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
266  * what it can get, which means any WinSock routines used outside
267  * that module must be exported from it as function pointers. So
268  * here they are.
269  */
270 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
271                       (SOCKET, HWND, u_int, long));
272 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
273                       (SOCKET, WSAEVENT, long));
274 DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
275                       (int, fd_set FAR *, fd_set FAR *,
276                        fd_set FAR *, const struct timeval FAR *));
277 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
278 DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
279                       (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
280
281 extern int socket_writable(SOCKET skt);
282
283 extern void socket_reselect_all(void);
284
285 /*
286  * Exports from winctrls.c.
287  */
288
289 struct ctlpos {
290     HWND hwnd;
291     WPARAM font;
292     int dlu4inpix;
293     int ypos, width;
294     int xoff;
295     int boxystart, boxid;
296     char *boxtext;
297 };
298
299 /*
300  * Exports from winutils.c.
301  */
302 typedef struct filereq_tag filereq; /* cwd for file requester */
303 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
304 filereq *filereq_new(void);
305 void filereq_free(filereq *state);
306 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
307 char *GetDlgItemText_alloc(HWND hwnd, int id);
308 void split_into_argv(char *, int *, char ***, char ***);
309
310 /*
311  * Private structure for prefslist state. Only in the header file
312  * so that we can delegate allocation to callers.
313  */
314 struct prefslist {
315     int listid, upbid, dnbid;
316     int srcitem;
317     int dummyitem;
318     int dragging;
319 };
320
321 /*
322  * This structure is passed to event handler functions as the `dlg'
323  * parameter, and hence is passed back to winctrls access functions.
324  */
325 struct dlgparam {
326     HWND hwnd;                         /* the hwnd of the dialog box */
327     struct winctrls *controltrees[8];  /* can have several of these */
328     int nctrltrees;
329     char *wintitle;                    /* title of actual window */
330     char *errtitle;                    /* title of error sub-messageboxes */
331     void *data;                        /* data to pass in refresh events */
332     union control *focused, *lastfocused; /* which ctrl has focus now/before */
333     char shortcuts[128];               /* track which shortcuts in use */
334     int coloursel_wanted;              /* has an event handler asked for
335                                         * a colour selector? */
336     struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
337     tree234 *privdata;                 /* stores per-control private data */
338     int ended, endresult;              /* has the dialog been ended? */
339     int fixed_pitch_fonts;             /* are we constrained to fixed fonts? */
340 };
341
342 /*
343  * Exports from winctrls.c.
344  */
345 void ctlposinit(struct ctlpos *cp, HWND hwnd,
346                 int leftborder, int rightborder, int topborder);
347 HWND doctl(struct ctlpos *cp, RECT r,
348            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
349 void bartitle(struct ctlpos *cp, char *name, int id);
350 void beginbox(struct ctlpos *cp, char *name, int idbox);
351 void endbox(struct ctlpos *cp);
352 void editboxfw(struct ctlpos *cp, int password, char *text,
353                int staticid, int editid);
354 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
355 void bareradioline(struct ctlpos *cp, int nacross, ...);
356 void radiobig(struct ctlpos *cp, char *text, int id, ...);
357 void checkbox(struct ctlpos *cp, char *text, int id);
358 void statictext(struct ctlpos *cp, char *text, int lines, int id);
359 void staticbtn(struct ctlpos *cp, char *stext, int sid,
360                char *btext, int bid);
361 void static2btn(struct ctlpos *cp, char *stext, int sid,
362                 char *btext1, int bid1, char *btext2, int bid2);
363 void staticedit(struct ctlpos *cp, char *stext,
364                 int sid, int eid, int percentedit);
365 void staticddl(struct ctlpos *cp, char *stext,
366                int sid, int lid, int percentlist);
367 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
368 void staticpassedit(struct ctlpos *cp, char *stext,
369                     int sid, int eid, int percentedit);
370 void bigeditctrl(struct ctlpos *cp, char *stext,
371                  int sid, int eid, int lines);
372 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
373 void editbutton(struct ctlpos *cp, char *stext, int sid,
374                 int eid, char *btext, int bid);
375 void sesssaver(struct ctlpos *cp, char *text,
376                int staticid, int editid, int listid, ...);
377 void envsetter(struct ctlpos *cp, char *stext, int sid,
378                char *e1stext, int e1sid, int e1id,
379                char *e2stext, int e2sid, int e2id,
380                int listid, char *b1text, int b1id, char *b2text, int b2id);
381 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
382                char *btext, int bid, int eid, char *s2text, int s2id);
383 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
384                 char *btext, int bid, ...);
385 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
386                char *stext, int sid, int listid, int upbid, int dnbid);
387 int handle_prefslist(struct prefslist *hdl,
388                      int *array, int maxmemb,
389                      int is_dlmsg, HWND hwnd,
390                      WPARAM wParam, LPARAM lParam);
391 void progressbar(struct ctlpos *cp, int id);
392 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
393                char *e1stext, int e1sid, int e1id,
394                char *e2stext, int e2sid, int e2id,
395                char *btext, int bid,
396                char *r1text, int r1id, char *r2text, int r2id);
397
398 void dlg_auto_set_fixed_pitch_flag(void *dlg);
399 int dlg_get_fixed_pitch_flag(void *dlg);
400 void dlg_set_fixed_pitch_flag(void *dlg, int flag);
401
402 #define MAX_SHORTCUTS_PER_CTRL 16
403
404 /*
405  * This structure is what's stored for each `union control' in the
406  * portable-dialog interface.
407  */
408 struct winctrl {
409     union control *ctrl;
410     /*
411      * The control may have several components at the Windows
412      * level, with different dialog IDs. To avoid needing N
413      * separate platformsidectrl structures (which could be stored
414      * separately in a tree234 so that lookup by ID worked), we
415      * impose the constraint that those IDs must be in a contiguous
416      * block.
417      */
418     int base_id;
419     int num_ids;
420     /*
421      * Remember what keyboard shortcuts were used by this control,
422      * so that when we remove it again we can take them out of the
423      * list in the dlgparam.
424      */
425     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
426     /*
427      * Some controls need a piece of allocated memory in which to
428      * store temporary data about the control.
429      */
430     void *data;
431 };
432 /*
433  * And this structure holds a set of the above, in two separate
434  * tree234s so that it can find an item by `union control' or by
435  * dialog ID.
436  */
437 struct winctrls {
438     tree234 *byctrl, *byid;
439 };
440 struct controlset;
441 struct controlbox;
442
443 void winctrl_init(struct winctrls *);
444 void winctrl_cleanup(struct winctrls *);
445 void winctrl_add(struct winctrls *, struct winctrl *);
446 void winctrl_remove(struct winctrls *, struct winctrl *);
447 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
448 struct winctrl *winctrl_findbyid(struct winctrls *, int);
449 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
450 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
451                     struct ctlpos *cp, struct controlset *s, int *id);
452 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
453                            WPARAM wParam, LPARAM lParam);
454 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
455 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
456
457 void dp_init(struct dlgparam *dp);
458 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
459 void dp_cleanup(struct dlgparam *dp);
460
461 /*
462  * Exports from wincfg.c.
463  */
464 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
465                           int midsession, int protocol);
466
467 /*
468  * Exports from windlg.c.
469  */
470 void defuse_showwindow(void);
471 int do_config(void);
472 int do_reconfig(HWND, int);
473 void showeventlog(HWND);
474 void showabout(HWND);
475 void force_normal(HWND hwnd);
476 void modal_about_box(HWND hwnd);
477 void show_help(HWND hwnd);
478
479 /*
480  * Exports from winmisc.c.
481  */
482 extern OSVERSIONINFO osVersion;
483 void dll_hijacking_protection(void);
484 BOOL init_winver(void);
485 HMODULE load_system32_dll(const char *libname);
486 const char *win_strerror(int error);
487
488 /*
489  * Exports from sizetip.c.
490  */
491 void UpdateSizeTip(HWND src, int cx, int cy);
492 void EnableSizeTip(int bEnable);
493
494 /*
495  * Exports from unicode.c.
496  */
497 struct unicode_data;
498 void init_ucs(Conf *, struct unicode_data *);
499
500 /*
501  * Exports from winhandl.c.
502  */
503 #define HANDLE_FLAG_OVERLAPPED 1
504 #define HANDLE_FLAG_IGNOREEOF 2
505 #define HANDLE_FLAG_UNITBUFFER 4
506 struct handle;
507 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
508 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
509 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
510                                 void *privdata, int flags);
511 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
512                                  void *privdata, int flags);
513 int handle_write(struct handle *h, const void *data, int len);
514 void handle_write_eof(struct handle *h);
515 HANDLE *handle_get_events(int *nevents);
516 void handle_free(struct handle *h);
517 void handle_got_event(HANDLE event);
518 void handle_unthrottle(struct handle *h, int backlog);
519 int handle_backlog(struct handle *h);
520 void *handle_get_privdata(struct handle *h);
521 struct handle *handle_add_foreign_event(HANDLE event,
522                                         void (*callback)(void *), void *ctx);
523
524 /*
525  * winpgntc.c needs to schedule callbacks for asynchronous agent
526  * requests. This has to be done differently in GUI and console, so
527  * there's an exported function used for the purpose.
528  * 
529  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
530  * synchronous in pscp and psftp.
531  */
532 void agent_schedule_callback(void (*callback)(void *, void *, int),
533                              void *callback_ctx, void *data, int len);
534 #define FLAG_SYNCAGENT 0x1000
535
536 /*
537  * Exports from winser.c.
538  */
539 extern Backend serial_backend;
540
541 /*
542  * Exports from winjump.c.
543  */
544 #define JUMPLIST_SUPPORTED             /* suppress #defines in putty.h */
545 void add_session_to_jumplist(const char * const sessionname);
546 void remove_session_from_jumplist(const char * const sessionname);
547 void clear_jumplist(void);
548 BOOL set_explicit_app_user_model_id();
549
550 /*
551  * Extra functions in winstore.c over and above the interface in
552  * storage.h.
553  *
554  * These functions manipulate the Registry section which mirrors the
555  * current Windows 7 jump list. (Because the real jump list storage is
556  * write-only, we need to keep another copy of whatever we put in it,
557  * so that we can put in a slightly modified version the next time.)
558  */
559
560 /* Adds a saved session to the registry jump list mirror. 'item' is a
561  * string naming a saved session. */
562 int add_to_jumplist_registry(const char *item);
563
564 /* Removes an item from the registry jump list mirror. */
565 int remove_from_jumplist_registry(const char *item);
566
567 /* Returns the current jump list entries from the registry. Caller
568  * must free the returned pointer, which points to a contiguous
569  * sequence of NUL-terminated strings in memory, terminated with an
570  * empty one. */
571 char *get_jumplist_registry_entries(void);
572
573 #endif