]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - windows/winstuff.h
Change how we handle the Ssh_gss_buf type. Previously, we defined it
[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 #include "tree234.h"
15
16 #include "winhelp.h"
17
18 struct Filename {
19     char path[FILENAME_MAX];
20 };
21 #define f_open(filename, mode, isprivate) ( fopen((filename).path, (mode)) )
22
23 struct FontSpec {
24     char name[64];
25     int isbold;
26     int height;
27     int charset;
28 };
29
30 #ifndef CLEARTYPE_QUALITY
31 #define CLEARTYPE_QUALITY 5
32 #endif
33 #define FONT_QUALITY(fq) ( \
34     (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
35     (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
36     (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
37     CLEARTYPE_QUALITY)
38
39 /*
40  * Where we can, we use GetWindowLongPtr and friends because they're
41  * more useful on 64-bit platforms, but they're a relatively recent
42  * innovation, missing from VC++ 6 and older MinGW.  Degrade nicely.
43  * (NB that on some systems, some of these things are available but
44  * not others...)
45  */
46
47 #ifndef GCLP_HCURSOR
48 /* GetClassLongPtr and friends */
49 #undef  GetClassLongPtr
50 #define GetClassLongPtr GetClassLong
51 #undef  SetClassLongPtr
52 #define SetClassLongPtr SetClassLong
53 #define GCLP_HCURSOR GCL_HCURSOR
54 /* GetWindowLongPtr and friends */
55 #undef  GetWindowLongPtr
56 #define GetWindowLongPtr GetWindowLong
57 #undef  SetWindowLongPtr
58 #define SetWindowLongPtr SetWindowLong
59 #undef  GWLP_USERDATA
60 #define GWLP_USERDATA GWL_USERDATA
61 #undef  DWLP_MSGRESULT
62 #define DWLP_MSGRESULT DWL_MSGRESULT
63 /* Since we've clobbered the above functions, we should clobber the
64  * associated type regardless of whether it's defined. */
65 #undef LONG_PTR
66 #define LONG_PTR LONG
67 #endif
68
69 #define BOXFLAGS DLGWINDOWEXTRA
70 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
71 #define DF_END 0x0001
72
73 /*
74  * Global variables. Most modules declare these `extern', but
75  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
76  * module, and so will get them properly defined.
77 */
78 #ifndef GLOBAL
79 #ifdef PUTTY_DO_GLOBALS
80 #define GLOBAL
81 #else
82 #define GLOBAL extern
83 #endif
84 #endif
85
86 #ifndef DONE_TYPEDEFS
87 #define DONE_TYPEDEFS
88 typedef struct config_tag Config;
89 typedef struct backend_tag Backend;
90 typedef struct terminal_tag Terminal;
91 #endif
92
93 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
94 #define PUTTY_REG_PARENT "Software\\SimonTatham"
95 #define PUTTY_REG_PARENT_CHILD "PuTTY"
96 #define PUTTY_REG_GPARENT "Software"
97 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
98
99 #define PUTTY_HELP_FILE "putty.hlp"
100 #define PUTTY_CHM_FILE "putty.chm"
101 #define PUTTY_HELP_CONTENTS "putty.cnt"
102
103 #define GETTICKCOUNT GetTickCount
104 #define CURSORBLINK GetCaretBlinkTime()
105 #define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
106
107 #define DEFAULT_CODEPAGE CP_ACP
108
109 typedef HDC Context;
110
111 #ifndef NO_GSSAPI
112 /*
113  * GSS-API stuff
114  */
115 typedef struct Ssh_gss_buf {
116     int length;
117     char *value;
118 } Ssh_gss_buf;
119
120 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
121 #endif
122
123 /*
124  * Window handles for the windows that can be running during a
125  * PuTTY session.
126  */
127 GLOBAL HWND hwnd;       /* the main terminal window */
128 GLOBAL HWND logbox;
129
130 /*
131  * The all-important instance handle.
132  */
133 GLOBAL HINSTANCE hinst;
134
135 /*
136  * Help file stuff in winhelp.c.
137  */
138 void init_help(void);
139 void shutdown_help(void);
140 int has_help(void);
141 void launch_help(HWND hwnd, const char *topic);
142 void quit_help(HWND hwnd);
143
144 /*
145  * The terminal and logging context are notionally local to the
146  * Windows front end, but they must be shared between window.c and
147  * windlg.c. Likewise the saved-sessions list.
148  */
149 GLOBAL Terminal *term;
150 GLOBAL void *logctx;
151
152 #define WM_NETEVENT  (WM_APP + 5)
153
154 /*
155  * On Windows, we send MA_2CLK as the only event marking the second
156  * press of a mouse button. Compare unix.h.
157  */
158 #define MULTICLICK_ONLY_EVENT 1
159
160 /*
161  * On Windows, data written to the clipboard must be NUL-terminated.
162  */
163 #define SELECTION_NUL_TERMINATED 1
164
165 /*
166  * On Windows, copying to the clipboard terminates lines with CRLF.
167  */
168 #define SEL_NL { 13, 10 }
169
170 /*
171  * sk_getxdmdata() does not exist under Windows (not that I
172  * couldn't write it if I wanted to, but I haven't bothered), so
173  * it's a macro which always returns NULL. With any luck this will
174  * cause the compiler to notice it can optimise away the
175  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
176  */
177 #define sk_getxdmdata(socket, lenp) (NULL)
178
179 /*
180  * File-selector filter strings used in the config box. On Windows,
181  * these strings are of exactly the type needed to go in
182  * `lpstrFilter' in an OPENFILENAME structure.
183  */
184 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
185                               "All Files (*.*)\0*\0\0\0")
186 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
187                                "All Files (*.*)\0*\0\0\0")
188
189 /*
190  * On some versions of Windows, it has been known for WM_TIMER to
191  * occasionally get its callback time simply wrong, and call us
192  * back several minutes early. Defining these symbols enables
193  * compensation code in timing.c.
194  */
195 #define TIMING_SYNC
196 #define TIMING_SYNC_TICKCOUNT
197
198 /*
199  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
200  * what it can get, which means any WinSock routines used outside
201  * that module must be exported from it as function pointers. So
202  * here they are.
203  */
204 extern int (WINAPI *p_WSAAsyncSelect)
205     (SOCKET s, HWND hWnd, u_int wMsg, long lEvent);
206 extern int (WINAPI *p_WSAEventSelect)
207     (SOCKET s, WSAEVENT hEventObject, long lNetworkEvents);
208 extern int (WINAPI *p_select)
209     (int nfds, fd_set FAR * readfds, fd_set FAR * writefds,
210      fd_set FAR *exceptfds, const struct timeval FAR * timeout);
211 extern int (WINAPI *p_WSAGetLastError)(void);
212 extern int (WINAPI *p_WSAEnumNetworkEvents)
213     (SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents);
214
215 extern int socket_writable(SOCKET skt);
216
217 extern void socket_reselect_all(void);
218
219 /*
220  * Exports from winctrls.c.
221  */
222
223 struct ctlpos {
224     HWND hwnd;
225     WPARAM font;
226     int dlu4inpix;
227     int ypos, width;
228     int xoff;
229     int boxystart, boxid;
230     char *boxtext;
231 };
232
233 /*
234  * Exports from winutils.c.
235  */
236 typedef struct filereq_tag filereq; /* cwd for file requester */
237 BOOL request_file(filereq *state, OPENFILENAME *of, int preserve, int save);
238 filereq *filereq_new(void);
239 void filereq_free(filereq *state);
240 int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid);
241 void split_into_argv(char *, int *, char ***, char ***);
242
243 /*
244  * Private structure for prefslist state. Only in the header file
245  * so that we can delegate allocation to callers.
246  */
247 struct prefslist {
248     int listid, upbid, dnbid;
249     int srcitem;
250     int dummyitem;
251     int dragging;
252 };
253
254 /*
255  * This structure is passed to event handler functions as the `dlg'
256  * parameter, and hence is passed back to winctrls access functions.
257  */
258 struct dlgparam {
259     HWND hwnd;                         /* the hwnd of the dialog box */
260     struct winctrls *controltrees[8];  /* can have several of these */
261     int nctrltrees;
262     char *wintitle;                    /* title of actual window */
263     char *errtitle;                    /* title of error sub-messageboxes */
264     void *data;                        /* data to pass in refresh events */
265     union control *focused, *lastfocused; /* which ctrl has focus now/before */
266     char shortcuts[128];               /* track which shortcuts in use */
267     int coloursel_wanted;              /* has an event handler asked for
268                                         * a colour selector? */
269     struct { unsigned char r, g, b, ok; } coloursel_result;   /* 0-255 */
270     tree234 *privdata;                 /* stores per-control private data */
271     int ended, endresult;              /* has the dialog been ended? */
272 };
273
274 /*
275  * Exports from winctrls.c.
276  */
277 void ctlposinit(struct ctlpos *cp, HWND hwnd,
278                 int leftborder, int rightborder, int topborder);
279 HWND doctl(struct ctlpos *cp, RECT r,
280            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
281 void bartitle(struct ctlpos *cp, char *name, int id);
282 void beginbox(struct ctlpos *cp, char *name, int idbox);
283 void endbox(struct ctlpos *cp);
284 void editboxfw(struct ctlpos *cp, int password, char *text,
285                int staticid, int editid);
286 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
287 void bareradioline(struct ctlpos *cp, int nacross, ...);
288 void radiobig(struct ctlpos *cp, char *text, int id, ...);
289 void checkbox(struct ctlpos *cp, char *text, int id);
290 void statictext(struct ctlpos *cp, char *text, int lines, int id);
291 void staticbtn(struct ctlpos *cp, char *stext, int sid,
292                char *btext, int bid);
293 void static2btn(struct ctlpos *cp, char *stext, int sid,
294                 char *btext1, int bid1, char *btext2, int bid2);
295 void staticedit(struct ctlpos *cp, char *stext,
296                 int sid, int eid, int percentedit);
297 void staticddl(struct ctlpos *cp, char *stext,
298                int sid, int lid, int percentlist);
299 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
300 void staticpassedit(struct ctlpos *cp, char *stext,
301                     int sid, int eid, int percentedit);
302 void bigeditctrl(struct ctlpos *cp, char *stext,
303                  int sid, int eid, int lines);
304 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
305 void editbutton(struct ctlpos *cp, char *stext, int sid,
306                 int eid, char *btext, int bid);
307 void sesssaver(struct ctlpos *cp, char *text,
308                int staticid, int editid, int listid, ...);
309 void envsetter(struct ctlpos *cp, char *stext, int sid,
310                char *e1stext, int e1sid, int e1id,
311                char *e2stext, int e2sid, int e2id,
312                int listid, char *b1text, int b1id, char *b2text, int b2id);
313 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
314                char *btext, int bid, int eid, char *s2text, int s2id);
315 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
316                 char *btext, int bid, ...);
317 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
318                char *stext, int sid, int listid, int upbid, int dnbid);
319 int handle_prefslist(struct prefslist *hdl,
320                      int *array, int maxmemb,
321                      int is_dlmsg, HWND hwnd,
322                      WPARAM wParam, LPARAM lParam);
323 void progressbar(struct ctlpos *cp, int id);
324 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
325                char *e1stext, int e1sid, int e1id,
326                char *e2stext, int e2sid, int e2id,
327                char *btext, int bid,
328                char *r1text, int r1id, char *r2text, int r2id);
329
330 #define MAX_SHORTCUTS_PER_CTRL 16
331
332 /*
333  * This structure is what's stored for each `union control' in the
334  * portable-dialog interface.
335  */
336 struct winctrl {
337     union control *ctrl;
338     /*
339      * The control may have several components at the Windows
340      * level, with different dialog IDs. To avoid needing N
341      * separate platformsidectrl structures (which could be stored
342      * separately in a tree234 so that lookup by ID worked), we
343      * impose the constraint that those IDs must be in a contiguous
344      * block.
345      */
346     int base_id;
347     int num_ids;
348     /*
349      * Remember what keyboard shortcuts were used by this control,
350      * so that when we remove it again we can take them out of the
351      * list in the dlgparam.
352      */
353     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
354     /*
355      * Some controls need a piece of allocated memory in which to
356      * store temporary data about the control.
357      */
358     void *data;
359 };
360 /*
361  * And this structure holds a set of the above, in two separate
362  * tree234s so that it can find an item by `union control' or by
363  * dialog ID.
364  */
365 struct winctrls {
366     tree234 *byctrl, *byid;
367 };
368 struct controlset;
369 struct controlbox;
370
371 void winctrl_init(struct winctrls *);
372 void winctrl_cleanup(struct winctrls *);
373 void winctrl_add(struct winctrls *, struct winctrl *);
374 void winctrl_remove(struct winctrls *, struct winctrl *);
375 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
376 struct winctrl *winctrl_findbyid(struct winctrls *, int);
377 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
378 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
379                     struct ctlpos *cp, struct controlset *s, int *id);
380 int winctrl_handle_command(struct dlgparam *dp, UINT msg,
381                            WPARAM wParam, LPARAM lParam);
382 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
383 int winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
384
385 void dp_init(struct dlgparam *dp);
386 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
387 void dp_cleanup(struct dlgparam *dp);
388
389 /*
390  * Exports from wincfg.c.
391  */
392 void win_setup_config_box(struct controlbox *b, HWND *hwndp, int has_help,
393                           int midsession, int protocol);
394
395 /*
396  * Exports from windlg.c.
397  */
398 void defuse_showwindow(void);
399 int do_config(void);
400 int do_reconfig(HWND, int);
401 void showeventlog(HWND);
402 void showabout(HWND);
403 void force_normal(HWND hwnd);
404 void modal_about_box(HWND hwnd);
405 void show_help(HWND hwnd);
406
407 /*
408  * Exports from winmisc.c.
409  */
410 extern OSVERSIONINFO osVersion;
411 BOOL init_winver(void);
412
413 /*
414  * Exports from sizetip.c.
415  */
416 void UpdateSizeTip(HWND src, int cx, int cy);
417 void EnableSizeTip(int bEnable);
418
419 /*
420  * Exports from unicode.c.
421  */
422 struct unicode_data;
423 void init_ucs(Config *, struct unicode_data *);
424
425 /*
426  * Exports from winhandl.c.
427  */
428 #define HANDLE_FLAG_OVERLAPPED 1
429 #define HANDLE_FLAG_IGNOREEOF 2
430 #define HANDLE_FLAG_UNITBUFFER 4
431 struct handle;
432 typedef int (*handle_inputfn_t)(struct handle *h, void *data, int len);
433 typedef void (*handle_outputfn_t)(struct handle *h, int new_backlog);
434 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
435                                 void *privdata, int flags);
436 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
437                                  void *privdata, int flags);
438 int handle_write(struct handle *h, const void *data, int len);
439 HANDLE *handle_get_events(int *nevents);
440 void handle_free(struct handle *h);
441 void handle_got_event(HANDLE event);
442 void handle_unthrottle(struct handle *h, int backlog);
443 int handle_backlog(struct handle *h);
444 void *handle_get_privdata(struct handle *h);
445
446 /*
447  * pageantc.c needs to schedule callbacks for asynchronous agent
448  * requests. This has to be done differently in GUI and console, so
449  * there's an exported function used for the purpose.
450  * 
451  * Also, we supply FLAG_SYNCAGENT to force agent requests to be
452  * synchronous in pscp and psftp.
453  */
454 void agent_schedule_callback(void (*callback)(void *, void *, int),
455                              void *callback_ctx, void *data, int len);
456 #define FLAG_SYNCAGENT 0x1000
457
458 /*
459  * Exports from winser.c.
460  */
461 extern Backend serial_backend;
462
463 #endif