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