Peter Schellenbach's patch: re-implement the PuTTY cryptographic
[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 GLOBAL HINSTANCE putty_inst;
18
19 #define ATTR_ACTCURS 0x80000000UL /* active cursor (block) */
20 #define ATTR_PASCURS 0x40000000UL /* passive cursor (box) */
21 #define ATTR_INVALID 0x20000000UL
22 #define ATTR_WRAPPED 0x10000000UL
23
24 #define ATTR_ASCII 0x00000000UL /* normal ASCII charset ESC ( B */
25 #define ATTR_GBCHR 0x00100000UL /* UK variant charset ESC ( A */
26 #define ATTR_LINEDRW 0x00200000UL /* line drawing charset ESC ( 0 */
27
28 #define ATTR_BOLD 0x00000100UL
29 #define ATTR_UNDER 0x00000200UL
30 #define ATTR_REVERSE 0x00000400UL
31 #define ATTR_BLINK 0x00000800UL
32 #define ATTR_FGMASK 0x0000F000UL
33 #define ATTR_BGMASK 0x000F0000UL
34 #define ATTR_FGSHIFT 12
35 #define ATTR_BGSHIFT 16
36
37 #define ATTR_DEFAULT 0x00098000UL
38 #define ATTR_DEFFG 0x00008000UL
39 #define ATTR_DEFBG 0x00090000UL
40 #define ATTR_CUR_XOR 0x000BA000UL
41 #define ERASE_CHAR (ATTR_DEFAULT | ' ')
42 #define ATTR_MASK 0xFFFFFF00UL
43 #define CHAR_MASK 0x000000FFUL
44
45 typedef HDC Context;
46 #define SEL_NL { 13, 10 }
47
48 GLOBAL int rows, cols, savelines;
49
50 GLOBAL int font_width, font_height;
51
52 #define INBUF_SIZE 2048
53 #define INBUF_MASK (INBUF_SIZE-1)
54 GLOBAL unsigned char inbuf[INBUF_SIZE];
55 GLOBAL int inbuf_head, inbuf_reap;
56
57 #define OUTBUF_SIZE 2048
58 #define OUTBUF_MASK (OUTBUF_SIZE-1)
59 GLOBAL unsigned char outbuf[OUTBUF_SIZE];
60 GLOBAL int outbuf_head, outbuf_reap;
61
62 GLOBAL int has_focus;
63
64 GLOBAL int app_cursor_keys, app_keypad_keys;
65
66 GLOBAL int seen_key_event;
67 GLOBAL int seen_disp_event;
68
69 GLOBAL int session_closed;
70
71 typedef enum {
72 US_NONE = 0, US_KEY = 1, US_DISP = 2, US_BOTH = 3
73 } Unscroll_Trigger;
74
75 GLOBAL Unscroll_Trigger unscroll_event;
76
77 GLOBAL char *logfile;
78
79 /*
80 * I've just looked in the windows standard headr files for WM_USER, there
81 * are hundreds of flags defined using the form WM_USER+123 so I've
82 * renumbered this NETEVENT value and the two in window.c
83 */
84 #define WM_XUSER (WM_USER + 0x2000)
85 #define WM_NETEVENT (WM_XUSER + 5)
86
87 typedef enum {
88 TS_AYT, TS_BRK, TS_SYNCH, TS_EC, TS_EL, TS_GA, TS_NOP, TS_ABORT,
89 TS_AO, TS_IP, TS_SUSP, TS_EOR, TS_EOF, TS_LECHO, TS_RECHO
90 } Telnet_Special;
91
92 typedef enum {
93 MB_NOTHING, MB_SELECT, MB_EXTEND, MB_PASTE
94 } Mouse_Button;
95
96 typedef enum {
97 MA_NOTHING, MA_CLICK, MA_2CLK, MA_3CLK, MA_DRAG, MA_RELEASE
98 } Mouse_Action;
99
100 typedef enum {
101 VT_XWINDOWS, VT_OEMANSI, VT_OEMONLY, VT_POORMAN
102 } VT_Mode;
103
104 typedef struct {
105 char *(*init) (HWND hwnd, char *host, int port, char **realhost);
106 int (*msg) (WPARAM wParam, LPARAM lParam);
107 void (*send) (char *buf, int len);
108 void (*size) (void);
109 void (*special) (Telnet_Special code);
110 } Backend;
111
112 GLOBAL Backend *back;
113
114 GLOBAL struct backend_list {
115 int protocol;
116 char *name;
117 Backend *backend;
118 } backends[];
119
120 typedef struct {
121 void (*send) (char *buf, int len);
122 } Ldisc;
123
124 GLOBAL Ldisc *ldisc;
125
126 typedef struct {
127 /* Basic options */
128 char host[512];
129 int port;
130 enum { PROT_RAW, PROT_TELNET, PROT_SSH } protocol;
131 int close_on_exit;
132 int warn_on_close;
133 /* SSH options */
134 int nopty;
135 enum { CIPHER_3DES, CIPHER_BLOWFISH, CIPHER_DES } cipher;
136 int try_tis_auth;
137 /* Telnet options */
138 char termtype[32];
139 char termspeed[32];
140 char environmt[1024]; /* VAR\tvalue\0VAR\tvalue\0\0 */
141 char username[32];
142 int rfc_environ;
143 /* Keyboard options */
144 int bksp_is_delete;
145 int rxvt_homeend;
146 int linux_funkeys;
147 int app_cursor;
148 int app_keypad;
149 int nethack_keypad;
150 int alt_f4; /* is it special? */
151 int alt_space; /* is it special? */
152 int ldisc_term;
153 int blink_cur;
154 /* Terminal options */
155 int savelines;
156 int dec_om;
157 int wrap_mode;
158 int lfhascr;
159 int win_name_always;
160 int width, height;
161 char font[64];
162 int fontisbold;
163 int fontheight;
164 int fontcharset;
165 VT_Mode vtmode;
166 /* Colour options */
167 int try_palette;
168 int bold_colour;
169 unsigned char colours[22][3];
170 /* Selection options */
171 int mouse_is_xterm;
172 short wordness[256];
173 /* russian language translation */
174 int xlat_enablekoiwin;
175 int xlat_88592w1250;
176 int xlat_capslockcyr;
177 } Config;
178
179 /*
180 * You can compile with -DSSH_DEFAULT to have ssh by default.
181 */
182 #ifndef SSH_DEFAULT
183 #define DEFAULT_PROTOCOL PROT_TELNET
184 #define DEFAULT_PORT 23
185 #else
186 #define DEFAULT_PROTOCOL PROT_SSH
187 #define DEFAULT_PORT 22
188 #endif
189
190 GLOBAL Config cfg;
191 GLOBAL int default_protocol;
192 GLOBAL int default_port;
193
194 struct RSAKey; /* be a little careful of scope */
195
196 /*
197 * Exports from window.c.
198 */
199 void request_resize (int, int, int);
200 void do_text (Context, int, int, char *, int, unsigned long);
201 void set_title (char *);
202 void set_icon (char *);
203 void set_sbar (int, int, int);
204 Context get_ctx(void);
205 void free_ctx (Context);
206 void palette_set (int, int, int, int);
207 void palette_reset (void);
208 void write_clip (void *, int);
209 void get_clip (void **, int *);
210 void optimised_move (int, int, int);
211 void fatalbox (char *, ...);
212 void beep (void);
213 #define OPTIMISE_IS_SCROLL 1
214
215 /*
216 * Exports from noise.c.
217 */
218 void noise_get_heavy(void (*func) (void *, int));
219 void noise_get_light(void (*func) (void *, int));
220 void noise_ultralight(DWORD data);
221 void random_save_seed(void);
222
223 /*
224 * Exports from windlg.c.
225 */
226 int do_config (void);
227 int do_reconfig (HWND);
228 void do_defaults (char *);
229 void logevent (char *);
230 void showeventlog (HWND);
231 void showabout (HWND);
232 void verify_ssh_host_key(char *host, char *keystr);
233 void get_sesslist(int allocate);
234
235 GLOBAL int nsessions;
236 GLOBAL char **sessions;
237
238 /*
239 * Exports from terminal.c.
240 */
241
242 void term_init (void);
243 void term_size (int, int, int);
244 void term_out (void);
245 void term_paint (Context, int, int, int, int);
246 void term_scroll (int, int);
247 void term_pwron (void);
248 void term_clrsb (void);
249 void term_mouse (Mouse_Button, Mouse_Action, int, int);
250 void term_deselect (void);
251 void term_update (void);
252 void term_invalidate(void);
253 void term_blink(int set_cursor);
254
255 /*
256 * Exports from raw.c.
257 */
258
259 extern Backend raw_backend;
260
261 /*
262 * Exports from telnet.c.
263 */
264
265 extern Backend telnet_backend;
266
267 /*
268 * Exports from ssh.c.
269 */
270
271 extern Backend ssh_backend;
272
273 /*
274 * Exports from ldisc.c.
275 */
276
277 extern Ldisc ldisc_term, ldisc_simple;
278
279 /*
280 * Exports from sshrand.c.
281 */
282
283 void random_add_noise(void *noise, int length);
284 void random_init(void);
285 int random_byte(void);
286 void random_get_savedata(void **data, int *len);
287
288 /*
289 * Exports from misc.c.
290 */
291
292 /* #define MALLOC_LOG do this if you suspect putty of leaking memory */
293 #ifdef MALLOC_LOG
294 #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z))
295 #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z))
296 #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z))
297 void mlog(char *, int);
298 #else
299 #define smalloc safemalloc
300 #define srealloc saferealloc
301 #define sfree safefree
302 #endif
303
304 void *safemalloc(size_t);
305 void *saferealloc(void *, size_t);
306 void safefree(void *);
307
308 /*
309 * Exports from version.c.
310 */
311 extern char ver[];
312
313 /*
314 * Exports from sizetip.c.
315 */
316 void UpdateSizeTip(HWND src, int cx, int cy);
317 void EnableSizeTip(int bEnable);
318
319 /*
320 * Exports from xlat.c.
321 */
322 unsigned char xlat_kbd2tty(unsigned char c);
323 unsigned char xlat_tty2scr(unsigned char c);
324 unsigned char xlat_latkbd2win(unsigned char c);
325
326 /*
327 * Exports from mscrypto.c
328 */
329 #ifdef MSCRYPTOAPI
330 int crypto_startup();
331 void crypto_wrapup();
332 #endif
333
334 /*
335 * A debug system.
336 */
337 #ifdef DEBUG
338 #include <stdarg.h>
339 #define debug(x) (dprintf x)
340 static void dprintf(char *fmt, ...) {
341 char buf[2048];
342 DWORD dw;
343 va_list ap;
344 static int gotconsole = 0;
345
346 if (!gotconsole) {
347 AllocConsole();
348 gotconsole = 1;
349 }
350
351 va_start(ap, fmt);
352 vsprintf(buf, fmt, ap);
353 WriteFile (GetStdHandle(STD_OUTPUT_HANDLE), buf, strlen(buf), &dw, NULL);
354 va_end(ap);
355 }
356 #else
357 #define debug(x)
358 #endif
359
360 #endif