putty.h 8.1 KB

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