]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - putty.h
Yeah. Some progress on Mac OS networking. Still some way to go, though.
[PuTTY.git] / putty.h
1 #ifndef PUTTY_PUTTY_H
2 #define PUTTY_PUTTY_H
3
4 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
5
6 #ifdef macintosh
7 #define OPTIMISE_SCROLL
8 #endif
9
10 #ifdef macintosh
11 #include <MacTypes.h>
12 #include <Palettes.h>
13 #include <Controls.h>
14 #include <Windows.h>
15 typedef UInt32 DWORD;
16 #endif /* macintosh */
17
18 #ifndef TRUE
19 #define TRUE 1
20 #endif
21 #ifndef FALSE
22 #define FALSE 0
23 #endif
24
25 #define ATTR_ACTCURS 0x80000000UL      /* active cursor (block) */
26 #define ATTR_PASCURS 0x40000000UL      /* passive cursor (box) */
27 #define ATTR_INVALID 0x20000000UL
28 #define ATTR_WRAPPED 0x10000000UL
29
30 #define ATTR_ASCII   0x00000000UL      /* normal ASCII charset ESC ( B */
31 #define ATTR_GBCHR   0x00100000UL      /* UK variant   charset ESC ( A */
32 #define ATTR_LINEDRW 0x00200000UL      /* line drawing charset ESC ( 0 */
33
34 #define ATTR_BOLD    0x00000100UL
35 #define ATTR_UNDER   0x00000200UL
36 #define ATTR_REVERSE 0x00000400UL
37 #define ATTR_FGMASK  0x0000F000UL
38 #define ATTR_BGMASK  0x000F0000UL
39 #define ATTR_FGSHIFT 12
40 #define ATTR_BGSHIFT 16
41
42 #define ATTR_DEFAULT 0x00098000UL
43 #define ATTR_DEFFG   0x00008000UL
44 #define ATTR_DEFBG   0x00090000UL
45 #define ATTR_CUR_XOR 0x000BA000UL
46 #define ERASE_CHAR   (ATTR_DEFAULT | ' ')
47 #define ATTR_MASK    0xFFFFFF00UL
48 #define CHAR_MASK    0x000000FFUL
49
50 #ifdef macintosh
51 #define SEL_NL { 13 }
52 #else
53 #define SEL_NL { 13, 10 }
54 #endif
55
56 /*
57  * Global variables. Most modules declare these `extern', but
58  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
59  * module, and so will get them properly defined.
60  */
61 #ifdef PUTTY_DO_GLOBALS
62 #define GLOBAL
63 #else
64 #define GLOBAL extern
65 #endif
66
67 #define INBUF_SIZE 2048
68 #define INBUF_MASK (INBUF_SIZE-1)
69
70 #define OUTBUF_SIZE 2048
71 #define OUTBUF_MASK (OUTBUF_SIZE-1)
72
73 #define WM_NETEVENT  (WM_USER + 1)
74
75 typedef enum {
76     TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
77     TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF
78 } Telnet_Special;
79
80 typedef enum {
81     MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
82 } Mouse_Button;
83
84 typedef enum {
85     MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
86 } Mouse_Action;
87
88 typedef enum {
89     VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
90 } VT_Mode;
91
92 typedef struct Session Session;
93 typedef struct Socket Socket;
94
95 /* Types of network event */
96
97 typedef enum {
98     NE_NULL,    /* Nothing happened */
99     NE_OPEN,    /* Connection successfully opened */
100     NE_NOHOST,  /* DNS lookup failed for some reason */
101     NE_REFUSED, /* Port unreachable */
102     NE_NOOPEN,  /* Connection failed to open for some other reason */
103     NE_DATA,    /* Incoming normal data */
104     NE_URGENT,  /* Incoming urgent data */
105     NE_CLOSING, /* Connection closed by remote host */
106     NE_CLOSED,  /* Connection close completed */
107     NE_TIMEOUT, /* Remote host vanished */
108     NE_ABORT,   /* Remote host reset connection */
109     NE_DIED,    /* Connection has failed for some other reason */
110 } Net_Event_Type;
111
112
113 typedef struct {
114     char *(*init) (Session *, char *host, int port);
115     int (*msg)(Session *, Socket *, Net_Event_Type);
116     void (*send) (Session *, char *buf, int len);
117     void (*size) (Session *);
118     void (*special) (Session *, Telnet_Special code);
119     void (*shutdown) (Session *);
120 } Backend;
121
122 typedef struct {
123     /* Basic options */
124     char host[512];
125     int port;
126     enum { PROT_TELNET, PROT_SSH } protocol;
127     int close_on_exit;
128     /* SSH options */
129     int nopty;
130     /* Telnet options */
131     char termtype[32];
132     char termspeed[32];
133     char environmt[1024];                    /* VAR\tvalue\0VAR\tvalue\0\0 */
134     char username[32];
135     int rfc_environ;
136     /* Keyboard options */
137     int bksp_is_delete;
138     int rxvt_homeend;
139     int linux_funkeys;
140     int app_cursor;
141     int app_keypad;
142     int meta_modifiers;
143     /* Terminal options */
144     int savelines;
145     int dec_om;
146     int wrap_mode;
147     int lfhascr;
148     int win_name_always;
149     int width, height;
150     char font[64];
151     int fontisbold;
152     int fontheight;
153     VT_Mode vtmode;
154     /* Colour options */
155     int try_palette;
156     int bold_colour;
157 #ifdef macintosh
158     PaletteHandle colours;
159 #else /* not macintosh */
160     unsigned char colours[22][3];
161 #endif /* not macintosh */
162     /* Selection options */
163     int implicit_copy;
164 #ifdef macintosh
165     int mouse_is_xterm;
166 #endif
167     short wordness[256];
168 } Config;
169
170 typedef struct {
171     /* Display buffers and pointers within them */
172     unsigned long *text;               /* buffer of text on terminal screen */
173     unsigned long *scrtop;             /* top of working screen */
174     unsigned long *disptop;            /* top of displayed screen */
175     unsigned long *sbtop;              /* top of scrollback */
176     unsigned long *cpos;               /* cursor position (convenience) */
177     unsigned long *disptext;           /* buffer of text on real screen */
178     unsigned long *wanttext;           /* buffer of text we want on screen */
179     unsigned long *alttext;            /* buffer of text on alt. screen */
180     unsigned char *selspace;           /* buffer for building selections in */
181
182     /* Current state */
183     unsigned long curr_attr;
184     int curs_x, curs_y;        /* cursor */
185     int cset;                  /* 0 or 1: which char set is in GL */
186     unsigned long cset_attr[2]; /* G0 and G1 char sets */
187
188     /* Saved state */
189     unsigned long  save_attr;
190     int save_x, save_y;        /* saved cursor position */
191     int save_cset, save_csattr;     /* saved with cursor position */
192
193     int marg_t, marg_b;        /* scroll margins */
194
195     /* Flags */
196     int dec_om;                /* DEC origin mode flag */
197     int wrap, wrapnext;        /* wrap flags */
198     int insert;                /* insert-mode flag */
199     int rvideo;                /* global reverse video flag */
200
201     /*
202      * Saved settings on the alternate screen.
203      */
204     int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins, alt_cset;
205     int alt_t, alt_b;
206     int alt_which;
207
208     /* Escape sequence handler state */
209 #define ARGS_MAX 32                    /* max # of esc sequence arguments */
210     int esc_args[ARGS_MAX];
211     int esc_nargs;
212     int esc_query;
213 #define OSC_STR_MAX 2048
214     int osc_strlen;
215     char osc_string[OSC_STR_MAX+1];
216     int osc_w;
217
218     unsigned char *tabs;
219     int nl_count;
220
221     enum {
222         TOPLEVEL, IGNORE_NEXT,
223         SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
224         SEEN_OSC, SEEN_OSC_P, SEEN_OSC_W, OSC_STRING, OSC_MAYBE_ST,
225         SEEN_ESCHASH
226     } termstate;
227
228     enum {
229         NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
230     } selstate;
231     enum {
232         SM_CHAR, SM_WORD, SM_LINE
233     } selmode;
234     unsigned long *selstart, *selend, *selanchor;
235     short wordness[256];
236 } Term_State;
237
238 typedef struct Session {
239     /* Config that created this session */
240     Config cfg;
241     /* Terminal emulator internal state */
242     Term_State ts;
243     /* Display state */
244     int rows, cols, savelines;
245     int font_width, font_height;
246     int has_focus;
247     /* Buffers */
248     unsigned char inbuf[INBUF_SIZE];
249     int inbuf_head, inbuf_reap;
250     unsigned char outbuf[OUTBUF_SIZE];
251     int outbuf_head, outbuf_reap;
252     /* Emulator state */
253     int app_cursor_keys, app_keypad_keys;
254     /* Backend */
255     Backend *back;
256     /* Conveniences */
257     unsigned long attr_mask;            /* Mask of attributes to display */
258 #ifdef macintosh
259     short               fontnum;
260     int                 font_ascent;
261     int                 font_leading;
262     int                 font_boldadjust;
263     WindowPtr           window;
264     PaletteHandle       palette;
265     ControlHandle       scrollbar;
266     WCTabHandle         wctab;
267 #endif
268 } Session;
269
270 typedef struct Socket Socket;
271
272 /*
273  * Exports from display system
274  */
275 extern void request_resize(Session *, int, int);
276 extern void do_text(Session *, int, int, char *, int, unsigned long);
277 extern void set_title(Session *, char *);
278 extern void set_icon(Session *, char *);
279 extern void set_sbar(Session *, int, int, int);
280 extern void pre_paint(Session *);
281 extern void post_paint(Session *);
282 extern void palette_set(Session *, int, int, int, int);
283 extern void palette_reset(Session *);
284 void write_clip (void *, int);
285 void get_clip (void **, int *);
286 extern void do_scroll(Session *, int, int, int);
287 void fatalbox (const char *, ...);
288 #ifdef macintosh
289 #pragma noreturn (fatalbox)
290 #endif
291 extern void beep (Session *s);
292
293 /*
294  * Exports from the network system
295  */
296
297 extern Socket *net_open(Session *, char *host, int port);
298 extern char *net_realname(Socket *);
299 extern int net_recv(Socket *, void *, int, int);
300 extern int net_send(Socket *, void *, int, int);
301 extern void net_close(Socket *); /* ask the remote end to close */
302 extern void net_destroy(Socket *); /* Tidy up */
303
304 /*
305  * Exports from noise.c.
306  */
307 void noise_get_heavy(void (*func) (void *, int));
308 void noise_get_light(void (*func) (void *, int));
309 void noise_ultralight(DWORD data);
310 void random_save_seed(void);
311
312 #ifndef macintosh
313 /*
314  * Exports from windlg.c.
315  */
316 int do_config (void);
317 int do_reconfig (HWND);
318 void do_defaults (char *);
319 void lognegot (char *);
320 void shownegot (HWND);
321 void showabout (HWND);
322 void verify_ssh_host_key(char *host, struct RSAKey *key);
323 #endif
324
325 /*
326  * Exports from terminal.c.
327  */
328
329 extern void term_init(Session *);
330 extern void term_size(Session *, int, int, int);
331 extern void term_out(Session *);
332 extern void term_paint(Session *, int, int, int, int);
333 extern void term_scroll(Session *, int, int);
334 extern void term_pwron(Session *);
335 extern void term_clrsb(Session *);
336 extern void term_mouse(Session *, Mouse_Button, Mouse_Action, int, int);
337 extern void term_copy(Session *);
338 extern void term_paste(Session *);
339 extern int term_hasselection(Session *);
340 extern void term_deselect (Session *);
341 extern void term_update (Session *);
342 extern void term_invalidate(Session *);
343
344 /*
345  * Exports from telnet.c.
346  */
347
348 extern Backend telnet_backend;
349
350 /*
351  * Exports from ssh.c.
352  */
353
354 extern Backend ssh_backend;
355
356 /*
357  * Exports from sshrand.c.
358  */
359
360 void random_add_noise(void *noise, int length);
361 void random_init(void);
362 int random_byte(void);
363 void random_get_savedata(void **data, int *len);
364
365 /*
366  * Exports from misc.c.
367  */
368
369 /* #define MALLOC_LOG  do this if you suspect putty of leaking memory */
370 #ifdef MALLOC_LOG
371 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
372 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
373 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
374 void mlog(char *, int);
375 #else
376 #define smalloc safemalloc
377 #define srealloc saferealloc
378 #define sfree safefree
379 #endif
380
381 void *safemalloc(size_t);
382 void *saferealloc(void *, size_t);
383 void safefree(void *);
384
385 /*
386  * Exports from testback.c
387  */
388
389 extern Backend null_backend;
390 extern Backend loop_backend;
391 extern Backend hexdump_backend;
392
393 /*
394  * Exports from version.c.
395  */
396 extern char ver[];
397
398 /*
399  * A debug system.
400  */
401 #ifdef DEBUG
402 #include <stdarg.h>
403 #define debug(x) (dprintf x)
404 static void dprintf(char *fmt, ...) {
405     char buf[2048];
406     DWORD dw;
407     va_list ap;
408     static int gotconsole = 0;
409
410     if (!gotconsole) {
411         AllocConsole();
412         gotconsole = 1;
413     }
414
415     va_start(ap, fmt);
416     vsprintf(buf, fmt, ap);
417     WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
418     va_end(ap);
419 }
420 #else
421 #define debug(x)
422 #endif
423
424 #endif