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

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 2 years ago

Update new version: 3.15.02

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