source: filezilla/trunk/fuentes/src/putty/windows/winstuff.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 18.2 KB
Line 
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
30struct Filename {
31    char *path;
32};
33#define f_open(filename, mode, isprivate) ( fopen((filename)->path, (mode)) )
34
35struct FontSpec {
36    char *name;
37    int isbold;
38    int height;
39    int charset;
40};
41struct FontSpec *fontspec_new(const char *name,
42                               int bold, int height, int charset);
43
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
53#define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
54                           * wchar_t strings with environment */
55
56/*
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
61 * not others...)
62 */
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
86#define BOXFLAGS DLGWINDOWEXTRA
87#define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
88#define DF_END 0x0001
89
90#ifndef NO_SECUREZEROMEMORY
91#define PLATFORM_HAS_SMEMCLR /* inhibit cross-platform one in misc.c */
92#endif
93
94#define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE   /* used in sshshare.c */
95
96/*
97 * Dynamically linked functions. These come in two flavours:
98 *
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.
102 *
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.)
110 *
111 * (DECL_WINDOWS_FUNCTION works with both these variants.)
112 */
113#define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params) \
114    typedef rettype (WINAPI *t_##name) params; \
115    linkage t_##name p_##name
116#define STR1(x) #x
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)
122
123/*
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.
127*/
128#ifndef GLOBAL
129#ifdef PUTTY_DO_GLOBALS
130#define GLOBAL
131#else
132#define GLOBAL extern
133#endif
134#endif
135
136#ifndef DONE_TYPEDEFS
137#define DONE_TYPEDEFS
138typedef struct conf_tag Conf;
139typedef struct backend_tag Backend;
140typedef struct terminal_tag Terminal;
141#endif
142
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"
148
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
156
157#define PUTTY_HELP_FILE "putty.hlp"
158#define PUTTY_CHM_FILE "putty.chm"
159#define PUTTY_HELP_CONTENTS "putty.cnt"
160
161#define GETTICKCOUNT GetTickCount
162#define CURSORBLINK GetCaretBlinkTime()
163#define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
164
165#define DEFAULT_CODEPAGE CP_ACP
166#define USES_VTLINE_HACK
167
168typedef HDC Context;
169
170typedef unsigned int uint32; /* int is 32-bits on Win32 and Win64. */
171#define PUTTY_UINT32_DEFINED
172
173#ifndef NO_GSSAPI
174/*
175 * GSS-API stuff
176 */
177#define GSS_CC CALLBACK
178/*
179typedef struct Ssh_gss_buf {
180    size_t length;
181    char *value;
182} Ssh_gss_buf;
183
184#define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
185typedef void *Ssh_gss_name;
186*/
187#endif
188
189/*
190 * Window handles for the windows that can be running during a
191 * PuTTY session.
192 */
193GLOBAL HWND hwnd;       /* the main terminal window */
194GLOBAL HWND logbox;
195
196/*
197 * The all-important instance handle.
198 */
199GLOBAL HINSTANCE hinst;
200
201/*
202 * Help file stuff in winhelp.c.
203 */
204void init_help(void);
205void shutdown_help(void);
206int has_help(void);
207void launch_help(HWND hwnd, const char *topic);
208void quit_help(HWND hwnd);
209
210/*
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.
214 */
215GLOBAL Terminal *term;
216GLOBAL void *logctx;
217
218#define WM_NETEVENT  (WM_APP + 5)
219
220/*
221 * On Windows, we send MA_2CLK as the only event marking the second
222 * press of a mouse button. Compare unix.h.
223 */
224#define MULTICLICK_ONLY_EVENT 1
225
226/*
227 * On Windows, data written to the clipboard must be NUL-terminated.
228 */
229#define SELECTION_NUL_TERMINATED 1
230
231/*
232 * On Windows, copying to the clipboard terminates lines with CRLF.
233 */
234#define SEL_NL { 13, 10 }
235
236/*
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 :-)
242 */
243#define sk_getxdmdata(socket, lenp) (NULL)
244
245/*
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.
249 */
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")
256
257/*
258 * Exports from winnet.c.
259 */
260extern int select_result(WPARAM, LPARAM);
261
262/*
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
266 * here they are.
267 */
268DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAAsyncSelect,
269                      (SOCKET, HWND, u_int, long));
270DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEventSelect,
271                      (SOCKET, WSAEVENT, long));
272DECL_WINDOWS_FUNCTION(GLOBAL, int, select,
273                      (int, fd_set FAR *, fd_set FAR *,
274                       fd_set FAR *, const struct timeval FAR *));
275DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAGetLastError, (void));
276DECL_WINDOWS_FUNCTION(GLOBAL, int, WSAEnumNetworkEvents,
277                      (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
278
279extern int socket_writable(SOCKET skt);
280
281extern void socket_reselect_all(void);
282
283/*
284 * Exports from winctrls.c.
285 */
286
287struct ctlpos {
288    HWND hwnd;
289    WPARAM font;
290    int dlu4inpix;
291    int ypos, width;
292    int xoff;
293    int boxystart, boxid;
294    char *boxtext;
295};
296
297/*
298 * Exports from winutils.c.
299 */
300typedef struct filereq_tag filereq; /* cwd for file requester */
301BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
302filereq *filereq_new(void);
303void filereq_free(filereq *state);
304int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
305char *GetDlgItemText_alloc(HWND hwnd, int id);
306void split_into_argv(char *, int *, char ***, char ***);
307
308/*
309 * Private structure for prefslist state. Only in the header file
310 * so that we can delegate allocation to callers.
311 */
312struct prefslist {
313    int listid, upbid, dnbid;
314    int srcitem;
315    int dummyitem;
316    int dragging;
317};
318
319/*
320 * This structure is passed to event handler functions as the `dlg'
321 * parameter, and hence is passed back to winctrls access functions.
322 */
323struct dlgparam {
324    HWND hwnd;                         /* the hwnd of the dialog box */
325    struct winctrls *controltrees[8];  /* can have several of these */
326    int nctrltrees;
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? */
338};
339
340/*
341 * Exports from winctrls.c.
342 */
343void ctlposinit(struct ctlpos *cp, HWND hwnd,
344                int leftborder, int rightborder, int topborder);
345HWND doctl(struct ctlpos *cp, RECT r,
346           char *wclass, int wstyle, int exstyle, char *wtext, int wid);
347void bartitle(struct ctlpos *cp, char *name, int id);
348void beginbox(struct ctlpos *cp, char *name, int idbox);
349void endbox(struct ctlpos *cp);
350void editboxfw(struct ctlpos *cp, int password, char *text,
351               int staticid, int editid);
352void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
353void bareradioline(struct ctlpos *cp, int nacross, ...);
354void radiobig(struct ctlpos *cp, char *text, int id, ...);
355void checkbox(struct ctlpos *cp, char *text, int id);
356void statictext(struct ctlpos *cp, char *text, int lines, int id);
357void staticbtn(struct ctlpos *cp, char *stext, int sid,
358               char *btext, int bid);
359void static2btn(struct ctlpos *cp, char *stext, int sid,
360                char *btext1, int bid1, char *btext2, int bid2);
361void staticedit(struct ctlpos *cp, char *stext,
362                int sid, int eid, int percentedit);
363void staticddl(struct ctlpos *cp, char *stext,
364               int sid, int lid, int percentlist);
365void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
366void staticpassedit(struct ctlpos *cp, char *stext,
367                    int sid, int eid, int percentedit);
368void bigeditctrl(struct ctlpos *cp, char *stext,
369                 int sid, int eid, int lines);
370void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
371void editbutton(struct ctlpos *cp, char *stext, int sid,
372                int eid, char *btext, int bid);
373void sesssaver(struct ctlpos *cp, char *text,
374               int staticid, int editid, int listid, ...);
375void 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);
379void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
380               char *btext, int bid, int eid, char *s2text, int s2id);
381void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
382                char *btext, int bid, ...);
383void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
384               char *stext, int sid, int listid, int upbid, int dnbid);
385int handle_prefslist(struct prefslist *hdl,
386                     int *array, int maxmemb,
387                     int is_dlmsg, HWND hwnd,
388                     WPARAM wParam, LPARAM lParam);
389void progressbar(struct ctlpos *cp, int id);
390void 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);
395
396void dlg_auto_set_fixed_pitch_flag(void *dlg);
397int dlg_get_fixed_pitch_flag(void *dlg);
398void dlg_set_fixed_pitch_flag(void *dlg, int flag);
399
400#define MAX_SHORTCUTS_PER_CTRL 16
401
402/*
403 * This structure is what's stored for each `union control' in the
404 * portable-dialog interface.
405 */
406struct winctrl {
407    union control *ctrl;
408    /*
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
414     * block.
415     */
416    int base_id;
417    int num_ids;
418    /*
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.
422     */
423    char shortcuts[MAX_SHORTCUTS_PER_CTRL];
424    /*
425     * Some controls need a piece of allocated memory in which to
426     * store temporary data about the control.
427     */
428    void *data;
429};
430/*
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
433 * dialog ID.
434 */
435struct winctrls {
436    tree234 *byctrl, *byid;
437};
438struct controlset;
439struct controlbox;
440
441void winctrl_init(struct winctrls *);
442void winctrl_cleanup(struct winctrls *);
443void winctrl_add(struct winctrls *, struct winctrl *);
444void winctrl_remove(struct winctrls *, struct winctrl *);
445struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
446struct winctrl *winctrl_findbyid(struct winctrls *, int);
447struct winctrl *winctrl_findbyindex(struct winctrls *, int);
448void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
449                    struct ctlpos *cp, struct controlset *s, int *id);
450int winctrl_handle_command(struct dlgparam *dp, UINT msg,
451                           WPARAM wParam, LPARAM lParam);
452void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
453int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
454
455void dp_init(struct dlgparam *dp);
456void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
457void dp_cleanup(struct dlgparam *dp);
458
459/*
460 * Exports from wincfg.c.
461 */
462void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
463                          int midsession, int protocol);
464
465/*
466 * Exports from windlg.c.
467 */
468void defuse_showwindow(void);
469int do_config(void);
470int do_reconfig(HWND, int);
471void showeventlog(HWND);
472void showabout(HWND);
473void force_normal(HWND hwnd);
474void modal_about_box(HWND hwnd);
475void show_help(HWND hwnd);
476
477/*
478 * Exports from winmisc.c.
479 */
480extern OSVERSIONINFO osVersion;
481BOOL init_winver(void);
482HMODULE load_system32_dll(const char *libname);
483const char *win_strerror(int error);
484
485/*
486 * Exports from sizetip.c.
487 */
488void UpdateSizeTip(HWND src, int cx, int cy);
489void EnableSizeTip(int bEnable);
490
491/*
492 * Exports from unicode.c.
493 */
494struct unicode_data;
495void init_ucs(Conf *, struct unicode_data *);
496
497/*
498 * Exports from winhandl.c.
499 */
500#define HANDLE_FLAG_OVERLAPPED 1
501#define HANDLE_FLAG_IGNOREEOF 2
502#define HANDLE_FLAG_UNITBUFFER 4
503struct handle;
504typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
505typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
506struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
507                                void *privdata, int flags);
508struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
509                                 void *privdata, int flags);
510int handle_write(struct handle *h, const void *data, int len);
511void handle_write_eof(struct handle *h);
512HANDLE *handle_get_events(int *nevents);
513void handle_free(struct handle *h);
514void handle_got_event(HANDLE event);
515void handle_unthrottle(struct handle *h, int backlog);
516int handle_backlog(struct handle *h);
517void *handle_get_privdata(struct handle *h);
518struct handle *handle_add_foreign_event(HANDLE event,
519                                        void (*callback)(void *), void *ctx);
520
521/*
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.
525 *
526 * Also, we supply FLAG_SYNCAGENT to force agent requests to be
527 * synchronous in pscp and psftp.
528 */
529void agent_schedule_callback(void (*callback)(void *, void *, int),
530                             void *callback_ctx, void *data, int len);
531#define FLAG_SYNCAGENT 0x1000
532
533/*
534 * Exports from winser.c.
535 */
536extern Backend serial_backend;
537
538/*
539 * Exports from winjump.c.
540 */
541#if 0
542#define JUMPLIST_SUPPORTED             /* suppress #defines in putty.h */
543#endif
544void add_session_to_jumplist(const char * const sessionname);
545void remove_session_from_jumplist(const char * const sessionname);
546void clear_jumplist(void);
547
548/*
549 * Extra functions in winstore.c over and above the interface in
550 * storage.h.
551 *
552 * These functions manipulate the Registry section which mirrors the
553 * current Windows 7 jump list. (Because the real jump list storage is
554 * write-only, we need to keep another copy of whatever we put in it,
555 * so that we can put in a slightly modified version the next time.)
556 */
557
558/* Adds a saved session to the registry jump list mirror. 'item' is a
559 * string naming a saved session. */
560int add_to_jumplist_registry(const char *item);
561
562/* Removes an item from the registry jump list mirror. */
563int remove_from_jumplist_registry(const char *item);
564
565/* Returns the current jump list entries from the registry. Caller
566 * must free the returned pointer, which points to a contiguous
567 * sequence of NUL-terminated strings in memory, terminated with an
568 * empty one. */
569char *get_jumplist_registry_entries(void);
570
571#endif
Note: See TracBrowser for help on using the repository browser.