2a3f028de4fdf8e137928600dab0d71e635c7d1a
[u/mdw/putty] / putty.h
1 #ifndef PUTTY_PUTTY_H
2 #define PUTTY_PUTTY_H
3
4 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
5
6 /*
7 * Global variables. Most modules declare these `extern', but
8 * window.c will do `#define PUTTY_DO_GLOBALS' before including this
9 * module, and so will get them properly defined.
10 */
11 #ifdef PUTTY_DO_GLOBALS
12 #define GLOBAL
13 #else
14 #define GLOBAL extern
15 #endif
16
17 #define ATTR_ACTCURS 0x80000000UL /* active cursor (block) */
18 #define ATTR_PASCURS 0x40000000UL /* passive cursor (box) */
19 #define ATTR_INVALID 0x20000000UL
20 #define ATTR_WRAPPED 0x10000000UL
21
22 #define ATTR_ASCII 0x00000000UL /* normal ASCII charset ESC ( B */
23 #define ATTR_GBCHR 0x00100000UL /* UK variant charset ESC ( A */
24 #define ATTR_LINEDRW 0x00200000UL /* line drawing charset ESC ( 0 */
25
26 #define ATTR_BOLD 0x00000100UL
27 #define ATTR_UNDER 0x00000200UL
28 #define ATTR_REVERSE 0x00000400UL
29 #define ATTR_FGMASK 0x0000F000UL
30 #define ATTR_BGMASK 0x000F0000UL
31 #define ATTR_FGSHIFT 12
32 #define ATTR_BGSHIFT 16
33
34 #define ATTR_DEFAULT 0x00098000UL
35 #define ATTR_DEFFG 0x00008000UL
36 #define ATTR_DEFBG 0x00090000UL
37 #define ATTR_CUR_XOR 0x000BA000UL
38 #define ERASE_CHAR (ATTR_DEFAULT | ' ')
39 #define ATTR_MASK 0xFFFFFF00UL
40 #define CHAR_MASK 0x000000FFUL
41
42 typedef HDC Context;
43 #define SEL_NL { 13, 10 }
44
45 GLOBAL int rows, cols, savelines;
46
47 GLOBAL int font_width, font_height;
48
49 #define INBUF_SIZE 2048
50 #define INBUF_MASK (INBUF_SIZE-1)
51 GLOBAL unsigned char inbuf[INBUF_SIZE];
52 GLOBAL int inbuf_head, inbuf_reap;
53
54 #define OUTBUF_SIZE 2048
55 #define OUTBUF_MASK (OUTBUF_SIZE-1)
56 GLOBAL unsigned char outbuf[OUTBUF_SIZE];
57 GLOBAL int outbuf_head, outbuf_reap;
58
59 GLOBAL int has_focus;
60
61 GLOBAL int app_cursor_keys, app_keypad_keys;
62
63 #define WM_NETEVENT (WM_USER + 1)
64
65 typedef enum {
66 TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
67 TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF
68 } Telnet_Special;
69
70 typedef enum {
71 MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
72 } Mouse_Button;
73
74 typedef enum {
75 MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
76 } Mouse_Action;
77
78 typedef enum {
79 VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
80 } VT_Mode;
81
82 typedef struct {
83 char *(*init) (HWND hwnd, char *host, int port, char **realhost);
84 int (*msg) (WPARAM wParam, LPARAM lParam);
85 void (*send) (char *buf, int len);
86 void (*size) (void);
87 void (*special) (Telnet_Special code);
88 } Backend;
89
90 GLOBAL Backend *back;
91
92 typedef struct {
93 /* Basic options */
94 char host[512];
95 int port;
96 enum { PROT_TELNET, PROT_SSH } protocol;
97 int close_on_exit;
98 /* SSH options */
99 int nopty;
100 enum { CIPHER_3DES, CIPHER_BLOWFISH, CIPHER_DES } cipher;
101 /* Telnet options */
102 char termtype[32];
103 char termspeed[32];
104 char environmt[1024]; /* VAR\tvalue\0VAR\tvalue\0\0 */
105 char username[32];
106 int rfc_environ;
107 /* Keyboard options */
108 int bksp_is_delete;
109 int rxvt_homeend;
110 int linux_funkeys;
111 int app_cursor;
112 int app_keypad;
113 /* Terminal options */
114 int savelines;
115 int dec_om;
116 int wrap_mode;
117 int lfhascr;
118 int win_name_always;
119 int width, height;
120 char font[64];
121 int fontisbold;
122 int fontheight;
123 VT_Mode vtmode;
124 /* Colour options */
125 int try_palette;
126 int bold_colour;
127 unsigned char colours[22][3];
128 /* Selection options */
129 int mouse_is_xterm;
130 short wordness[256];
131 } Config;
132
133 /*
134 * You can compile with -DSSH_DEFAULT to have ssh by default.
135 */
136 #ifndef SSH_DEFAULT
137 #define DEFAULT_PROTOCOL PROT_TELNET
138 #define DEFAULT_PORT 23
139 #else
140 #define DEFAULT_PROTOCOL PROT_SSH
141 #define DEFAULT_PORT 22
142 #endif
143
144 GLOBAL Config cfg;
145 GLOBAL int default_protocol;
146 GLOBAL int default_port;
147
148 /*
149 * Exports from window.c.
150 */
151 void request_resize (int, int);
152 void do_text (Context, int, int, char *, int, unsigned long);
153 void set_title (char *);
154 void set_icon (char *);
155 void set_sbar (int, int, int);
156 Context get_ctx(void);
157 void free_ctx (Context);
158 void palette_set (int, int, int, int);
159 void palette_reset (void);
160 void write_clip (void *, int);
161 void get_clip (void **, int *);
162 void optimised_move (int, int, int);
163 void fatalbox (char *, ...);
164 void beep (void);
165 #define OPTIMISE_IS_SCROLL 1
166
167 /*
168 * Exports from noise.c.
169 */
170 void noise_get_heavy(void (*func) (void *, int));
171 void noise_get_light(void (*func) (void *, int));
172 void noise_ultralight(DWORD data);
173 void random_save_seed(void);
174
175 /*
176 * Exports from windlg.c.
177 */
178 int do_config (void);
179 int do_reconfig (HWND);
180 void do_defaults (char *);
181 void lognegot (char *);
182 void shownegot (HWND);
183 void showabout (HWND);
184 void verify_ssh_host_key(char *host, struct RSAKey *key);
185 void get_sesslist(int allocate);
186
187 GLOBAL int nsessions;
188 GLOBAL char **sessions;
189
190 /*
191 * Exports from terminal.c.
192 */
193
194 void term_init (void);
195 void term_size (int, int, int);
196 void term_out (void);
197 void term_paint (Context, int, int, int, int);
198 void term_scroll (int, int);
199 void term_pwron (void);
200 void term_clrsb (void);
201 void term_mouse (Mouse_Button, Mouse_Action, int, int);
202 void term_deselect (void);
203 void term_update (void);
204 void term_invalidate(void);
205
206 /*
207 * Exports from telnet.c.
208 */
209
210 extern Backend telnet_backend;
211
212 /*
213 * Exports from ssh.c.
214 */
215
216 extern Backend ssh_backend;
217
218 /*
219 * Exports from sshrand.c.
220 */
221
222 void random_add_noise(void *noise, int length);
223 void random_init(void);
224 int random_byte(void);
225 void random_get_savedata(void **data, int *len);
226
227 /*
228 * Exports from misc.c.
229 */
230
231 /* #define MALLOC_LOG do this if you suspect putty of leaking memory */
232 #ifdef MALLOC_LOG
233 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
234 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
235 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
236 void mlog(char *, int);
237 #else
238 #define smalloc safemalloc
239 #define srealloc saferealloc
240 #define sfree safefree
241 #endif
242
243 void *safemalloc(size_t);
244 void *saferealloc(void *, size_t);
245 void safefree(void *);
246
247 /*
248 * Exports from version.c.
249 */
250 extern char ver[];
251
252 /*
253 * A debug system.
254 */
255 #ifdef DEBUG
256 #include <stdarg.h>
257 #define debug(x) (dprintf x)
258 static void dprintf(char *fmt, ...) {
259 char buf[2048];
260 DWORD dw;
261 va_list ap;
262 static int gotconsole = 0;
263
264 if (!gotconsole) {
265 AllocConsole();
266 gotconsole = 1;
267 }
268
269 va_start(ap, fmt);
270 vsprintf(buf, fmt, ap);
271 WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
272 va_end(ap);
273 }
274 #else
275 #define debug(x)
276 #endif
277
278 #endif