5e1a8e27 |
1 | #include <windows.h> |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
5e1a8e27 |
4 | |
5 | #include "putty.h" |
6 | |
7 | #ifndef FALSE |
8 | #define FALSE 0 |
9 | #endif |
10 | #ifndef TRUE |
11 | #define TRUE 1 |
12 | #endif |
13 | |
8df7a775 |
14 | static Socket s = NULL; |
5e1a8e27 |
15 | |
5e1a8e27 |
16 | static void raw_size(void); |
17 | |
18 | static int sb_opt, sb_len; |
19 | static char *sb_buf = NULL; |
20 | static int sb_size = 0; |
21 | #define SB_DELTA 1024 |
22 | |
8df7a775 |
23 | static void c_write (char *buf, int len) { |
24 | from_backend(0, buf, len); |
5e1a8e27 |
25 | } |
26 | |
7dbb9f56 |
27 | static int raw_receive (Socket skt, int urgent, char *data, int len) { |
2c94fd1c |
28 | if (urgent==3) { |
29 | /* A socket error has occurred. */ |
b47b2198 |
30 | sk_close(s); |
7dbb9f56 |
31 | s = NULL; |
2c94fd1c |
32 | connection_fatal(data); |
33 | len = 0; |
b47b2198 |
34 | return 0; |
35 | } else if (!len) { |
8df7a775 |
36 | /* Connection has closed. */ |
37 | sk_close(s); |
38 | s = NULL; |
39 | return 0; |
5e1a8e27 |
40 | } |
8df7a775 |
41 | c_write(data, len); |
42 | return 1; |
5e1a8e27 |
43 | } |
44 | |
45 | /* |
8df7a775 |
46 | * Called to set up the raw connection. |
47 | * |
5e1a8e27 |
48 | * Returns an error message, or NULL on success. |
49 | * |
50 | * Also places the canonical host name into `realhost'. |
51 | */ |
8df7a775 |
52 | static char *raw_init (char *host, int port, char **realhost) { |
53 | SockAddr addr; |
54 | char *err; |
5e1a8e27 |
55 | |
56 | /* |
57 | * Try to find host. |
58 | */ |
8df7a775 |
59 | addr = sk_namelookup(host, realhost); |
60 | if ( (err = sk_addr_error(addr)) ) |
61 | return err; |
5e1a8e27 |
62 | |
63 | if (port < 0) |
64 | port = 23; /* default telnet port */ |
65 | |
66 | /* |
67 | * Open socket. |
68 | */ |
4b1e8acc |
69 | s = sk_new(addr, port, 0, 1, raw_receive); |
8df7a775 |
70 | if ( (err = sk_socket_error(s)) ) |
71 | return err; |
5e1a8e27 |
72 | |
8df7a775 |
73 | sk_addr_free(addr); |
5e1a8e27 |
74 | |
75 | return NULL; |
76 | } |
77 | |
78 | /* |
5e1a8e27 |
79 | * Called to send data down the raw connection. |
80 | */ |
81 | static void raw_send (char *buf, int len) { |
82 | |
8df7a775 |
83 | if (s == NULL) |
5e1a8e27 |
84 | return; |
85 | |
8df7a775 |
86 | sk_write(s, buf, len); |
5e1a8e27 |
87 | } |
88 | |
89 | /* |
90 | * Called to set the size of the window |
91 | */ |
92 | static void raw_size(void) { |
93 | /* Do nothing! */ |
94 | return; |
95 | } |
96 | |
97 | /* |
98 | * Send raw special codes. |
99 | */ |
100 | static void raw_special (Telnet_Special code) { |
101 | /* Do nothing! */ |
102 | return; |
103 | } |
104 | |
8df7a775 |
105 | static Socket raw_socket(void) { return s; } |
8ccc75b0 |
106 | |
107 | static int raw_sendok(void) { return 1; } |
4017be6d |
108 | |
0965bee0 |
109 | static int raw_ldisc(int option) { |
110 | if (option == LD_EDIT || option == LD_ECHO) |
111 | return 1; |
112 | return 0; |
113 | } |
114 | |
5e1a8e27 |
115 | Backend raw_backend = { |
116 | raw_init, |
5e1a8e27 |
117 | raw_send, |
118 | raw_size, |
4017be6d |
119 | raw_special, |
8ccc75b0 |
120 | raw_socket, |
97db3be4 |
121 | raw_sendok, |
0965bee0 |
122 | raw_ldisc, |
97db3be4 |
123 | 1 |
5e1a8e27 |
124 | }; |