]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - putty.h
Lots of MacTCP networking stuff. I think all the code's written, but it
[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_SENT,    /* Used internally by Mac network stack */
106     NE_CLOSING, /* Connection closed by remote host */
107     NE_CLOSED,  /* Connection close completed */
108     NE_TIMEOUT, /* Remote host vanished */
109     NE_ABORT,   /* Remote host reset connection */
110     NE_DIED,    /* Connection has failed for some other reason */
111 } Net_Event_Type;
112
113 #ifdef macintosh
114 typedef Socket *SOCKET;
115 #define INVALID_SOCKET NULL
116 #endif
117
118 typedef struct {
119     char *(*init) (Session *);
120     int (*msg)(Session *, SOCKET, Net_Event_Type);
121     void (*send) (Session *, char *buf, int len);
122     void (*size) (Session *);
123     void (*special) (Session *, Telnet_Special code);
124     void (*shutdown) (Session *);
125 } Backend;
126
127 typedef struct {
128     /* Basic options */
129     char host[512];
130     int port;
131     enum { PROT_TELNET, PROT_SSH } protocol;
132     int close_on_exit;
133     /* SSH options */
134     int nopty;
135     /* Telnet options */
136     char termtype[32];
137     char termspeed[32];
138     char environmt[1024];                    /* VAR\tvalue\0VAR\tvalue\0\0 */
139     char username[32];
140     int rfc_environ;
141     /* Keyboard options */
142     int bksp_is_delete;
143     int rxvt_homeend;
144     int linux_funkeys;
145     int app_cursor;
146     int app_keypad;
147     int meta_modifiers;
148     /* Terminal options */
149     int savelines;
150     int dec_om;
151     int wrap_mode;
152     int lfhascr;
153     int win_name_always;
154     int width, height;
155     char font[64];
156     int fontisbold;
157     int fontheight;
158     VT_Mode vtmode;
159     /* Colour options */
160     int try_palette;
161     int bold_colour;
162 #ifdef macintosh
163     PaletteHandle colours;
164 #else /* not macintosh */
165     unsigned char colours[22][3];
166 #endif /* not macintosh */
167     /* Selection options */
168     int implicit_copy;
169 #ifdef macintosh
170     int mouse_is_xterm;
171 #endif
172     short wordness[256];
173 } Config;
174
175 typedef struct {
176     /* Display buffers and pointers within them */
177     unsigned long *text;               /* buffer of text on terminal screen */
178     unsigned long *scrtop;             /* top of working screen */
179     unsigned long *disptop;            /* top of displayed screen */
180     unsigned long *sbtop;              /* top of scrollback */
181     unsigned long *cpos;               /* cursor position (convenience) */
182     unsigned long *disptext;           /* buffer of text on real screen */
183     unsigned long *wanttext;           /* buffer of text we want on screen */
184     unsigned long *alttext;            /* buffer of text on alt. screen */
185     unsigned char *selspace;           /* buffer for building selections in */
186
187     /* Current state */
188     unsigned long curr_attr;
189     int curs_x, curs_y;        /* cursor */
190     int cset;                  /* 0 or 1: which char set is in GL */
191     unsigned long cset_attr[2]; /* G0 and G1 char sets */
192
193     /* Saved state */
194     unsigned long  save_attr;
195     int save_x, save_y;        /* saved cursor position */
196     int save_cset, save_csattr;     /* saved with cursor position */
197
198     int marg_t, marg_b;        /* scroll margins */
199
200     /* Flags */
201     int dec_om;                /* DEC origin mode flag */
202     int wrap, wrapnext;        /* wrap flags */
203     int insert;                /* insert-mode flag */
204     int rvideo;                /* global reverse video flag */
205
206     /*
207      * Saved settings on the alternate screen.
208      */
209     int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins, alt_cset;
210     int alt_t, alt_b;
211     int alt_which;
212
213     /* Escape sequence handler state */
214 #define ARGS_MAX 32                    /* max # of esc sequence arguments */
215     int esc_args[ARGS_MAX];
216     int esc_nargs;
217     int esc_query;
218 #define OSC_STR_MAX 2048
219     int osc_strlen;
220     char osc_string[OSC_STR_MAX+1];
221     int osc_w;
222
223     unsigned char *tabs;
224     int nl_count;
225
226     enum {
227         TOPLEVEL, IGNORE_NEXT,
228         SEEN_ESC, SEEN_CSI, SET_GL, SET_GR,
229         SEEN_OSC, SEEN_OSC_P, SEEN_OSC_W, OSC_STRING, OSC_MAYBE_ST,
230         SEEN_ESCHASH
231     } termstate;
232
233     enum {
234         NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
235     } selstate;
236     enum {
237         SM_CHAR, SM_WORD, SM_LINE
238     } selmode;
239     unsigned long *selstart, *selend, *selanchor;
240     short wordness[256];
241 } Term_State;
242
243 typedef struct Session {
244     /* Config that created this session */
245     Config cfg;
246     /* Terminal emulator internal state */
247     Term_State ts;
248     /* Display state */
249     int rows, cols, savelines;
250     int font_width, font_height;
251     int has_focus;
252     /* Buffers */
253     unsigned char inbuf[INBUF_SIZE];
254     int inbuf_head, inbuf_reap;
255     unsigned char outbuf[OUTBUF_SIZE];
256     int outbuf_head, outbuf_reap;
257     /* Emulator state */
258     int app_cursor_keys, app_keypad_keys;
259     /* Backend */
260     Backend *back;
261     /* Conveniences */
262     unsigned long attr_mask;            /* Mask of attributes to display */
263 #ifdef macintosh
264     short               fontnum;
265     int                 font_ascent;
266     int                 font_leading;
267     int                 font_boldadjust;
268     WindowPtr           window;
269     PaletteHandle       palette;
270     ControlHandle       scrollbar;
271     WCTabHandle         wctab;
272 #endif
273 } Session;
274
275 typedef struct Socket Socket;
276
277 /*
278  * Exports from display system
279  */
280 extern void request_resize(Session *, int, int);
281 extern void do_text(Session *, int, int, char *, int, unsigned long);
282 extern void set_title(Session *, char *);
283 extern void set_icon(Session *, char *);
284 extern void set_sbar(Session *, int, int, int);
285 extern void pre_paint(Session *);
286 extern void post_paint(Session *);
287 extern void palette_set(Session *, int, int, int, int);
288 extern void palette_reset(Session *);
289 extern void write_clip (void *, int);
290 extern void get_clip (void **, int *);
291 extern void do_scroll(Session *, int, int, int);
292 extern void fatalbox(const char *, ...);
293 #ifdef macintosh
294 #pragma noreturn (fatalbox)
295 #endif
296 extern void beep(Session *s);
297 extern void lognegot(const char *);
298
299 /*
300  * Exports from the network system
301  */
302
303 extern Socket *net_open(Session *, char *host, int port);
304 extern char *net_realname(Socket *);
305 extern int net_recv(Socket *, void *, int, int);
306 extern int net_send(Socket *, void *, int, int);
307 #define SEND_PUSH 0x01
308 #define SEND_URG 0x02
309 extern void net_close(Socket *); /* ask the remote end to close */
310 extern void net_destroy(Socket *); /* Tidy up */
311
312 /*
313  * Exports from noise.c.
314  */
315 void noise_get_heavy(void (*func) (void *, int));
316 void noise_get_light(void (*func) (void *, int));
317 void noise_ultralight(DWORD data);
318 void random_save_seed(void);
319
320 #ifndef macintosh
321 /*
322  * Exports from windlg.c.
323  */
324 int do_config (void);
325 int do_reconfig (HWND);
326 void do_defaults (char *);
327 void lognegot (char *);
328 void shownegot (HWND);
329 void showabout (HWND);
330 void verify_ssh_host_key(char *host, struct RSAKey *key);
331 #endif
332
333 /*
334  * Exports from terminal.c.
335  */
336
337 extern void term_init(Session *);
338 extern void term_size(Session *, int, int, int);
339 extern void term_out(Session *);
340 extern void term_paint(Session *, int, int, int, int);
341 extern void term_scroll(Session *, int, int);
342 extern void term_pwron(Session *);
343 extern void term_clrsb(Session *);
344 extern void term_mouse(Session *, Mouse_Button, Mouse_Action, int, int);
345 extern void term_copy(Session *);
346 extern void term_paste(Session *);
347 extern int term_hasselection(Session *);
348 extern void term_deselect (Session *);
349 extern void term_update (Session *);
350 extern void term_invalidate(Session *);
351
352 /*
353  * Exports from telnet.c.
354  */
355
356 extern Backend telnet_backend;
357
358 /*
359  * Exports from ssh.c.
360  */
361
362 extern Backend ssh_backend;
363
364 /*
365  * Exports from sshrand.c.
366  */
367
368 void random_add_noise(void *noise, int length);
369 void random_init(void);
370 int random_byte(void);
371 void random_get_savedata(void **data, int *len);
372
373 /*
374  * Exports from misc.c.
375  */
376
377 /* #define MALLOC_LOG  do this if you suspect putty of leaking memory */
378 #ifdef MALLOC_LOG
379 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
380 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
381 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
382 void mlog(char *, int);
383 #else
384 #define smalloc safemalloc
385 #define srealloc saferealloc
386 #define sfree safefree
387 #endif
388
389 void *safemalloc(size_t);
390 void *saferealloc(void *, size_t);
391 void safefree(void *);
392
393 /*
394  * Exports from testback.c
395  */
396
397 extern Backend null_backend;
398 extern Backend loop_backend;
399 extern Backend hexdump_backend;
400
401 /*
402  * Exports from version.c.
403  */
404 extern char ver[];
405
406 /*
407  * A debug system.
408  */
409 #ifdef DEBUG
410 #include <stdarg.h>
411 #define debug(x) (dprintf x)
412 static void dprintf(char *fmt, ...) {
413     char buf[2048];
414     DWORD dw;
415     va_list ap;
416     static int gotconsole = 0;
417
418     if (!gotconsole) {
419         AllocConsole();
420         gotconsole = 1;
421     }
422
423     va_start(ap, fmt);
424     vsprintf(buf, fmt, ap);
425     WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
426     va_end(ap);
427 }
428 #else
429 #define debug(x)
430 #endif
431
432 #endif