Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 301 lines (255 sloc) 5.907 kb
eaf1e20 Sprinkle some header comments in various files in an attempt to expla…
jacob authored
1 /*
2 * "Raw" backend.
3 */
4
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 #include "putty.h"
9
10 #ifndef FALSE
11 #define FALSE 0
12 #endif
13 #ifndef TRUE
14 #define TRUE 1
15 #endif
16
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
17 #define RAW_MAX_BACKLOG 4096
18
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
19 typedef struct raw_backend_data {
20 const struct plug_function_table *fn;
21 /* the above field _must_ be first in the structure */
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
22
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
23 Socket s;
24 int bufsize;
25 void *frontend;
26 } *Raw;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
27
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
28 static void raw_size(void *handle, int width, int height);
29
30 static void c_write(Raw raw, char *buf, int len)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
31 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
32 int backlog = from_backend(raw->frontend, 0, buf, len);
33 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
34 }
35
7555d6a Support for falling back through the list of addresses returned from
simon authored
36 static void raw_log(Plug plug, int type, SockAddr addr, int port,
37 const char *error_msg, int error_code)
38 {
39 Raw raw = (Raw) plug;
40 char addrbuf[256], *msg;
41
42 sk_getaddr(addr, addrbuf, lenof(addrbuf));
43
44 if (type == 0)
45 msg = dupprintf("Connecting to %s port %d", addrbuf, port);
46 else
47 msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
48
49 logevent(raw->frontend, msg);
50 }
51
cbe2d68 Colin's const-fixing Patch Of Death. Seems to build fine on Windows
simon authored
52 static int raw_closing(Plug plug, const char *error_msg, int error_code,
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
53 int calling_back)
54 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
55 Raw raw = (Raw) plug;
56
57 if (raw->s) {
58 sk_close(raw->s);
59 raw->s = NULL;
39934de New timing infrastructure. There's a new function schedule_timer()
simon authored
60 notify_remote_exit(raw->frontend);
f3ab576 Yet another possible segfault path in the backends fixed. I don't
simon authored
61 }
7e78000 Dave Hinton's modifications to the network layer interface, which
simon authored
62 if (error_msg) {
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
63 /* A socket error has occurred. */
a832773 Yet more global-removal. The static variables in logging.c are now
simon authored
64 logevent(raw->frontend, error_msg);
971bcc0 Colin's and my fixes to connection_fatal().
simon authored
65 connection_fatal(raw->frontend, "%s", error_msg);
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
66 } /* Otherwise, the remote side closed the connection normally. */
7e78000 Dave Hinton's modifications to the network layer interface, which
simon authored
67 return 0;
68 }
69
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
70 static int raw_receive(Plug plug, int urgent, char *data, int len)
71 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
72 Raw raw = (Raw) plug;
73 c_write(raw, data, len);
8df7a77 Created a shiny new abstraction for the socket handling. Has many
simon authored
74 return 1;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
75 }
76
3ad9d39 Robert de Bath's asynchronous-connect patch. Helps a lot in port
simon authored
77 static void raw_sent(Plug plug, int bufsize)
78 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
79 Raw raw = (Raw) plug;
80 raw->bufsize = bufsize;
3ad9d39 Robert de Bath's asynchronous-connect patch. Helps a lot in port
simon authored
81 }
82
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
83 /*
8df7a77 Created a shiny new abstraction for the socket handling. Has many
simon authored
84 * Called to set up the raw connection.
85 *
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
86 * Returns an error message, or NULL on success.
87 *
6e1ebb7 `realhost', passed back from all the backend init functions, was
simon authored
88 * Also places the canonical host name into `realhost'. It must be
89 * freed by the caller.
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
90 */
cbe2d68 Colin's const-fixing Patch Of Death. Seems to build fine on Windows
simon authored
91 static const char *raw_init(void *frontend_handle, void **backend_handle,
92 Config *cfg,
79bf227 Add a configuration option for TCP keepalives (SO_KEEPALIVE), default…
jacob authored
93 char *host, int port, char **realhost, int nodelay,
94 int keepalive)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
95 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
96 static const struct plug_function_table fn_table = {
7555d6a Support for falling back through the list of addresses returned from
simon authored
97 raw_log,
7e78000 Dave Hinton's modifications to the network layer interface, which
simon authored
98 raw_closing,
3ad9d39 Robert de Bath's asynchronous-connect patch. Helps a lot in port
simon authored
99 raw_receive,
100 raw_sent
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
101 };
8df7a77 Created a shiny new abstraction for the socket handling. Has many
simon authored
102 SockAddr addr;
cbe2d68 Colin's const-fixing Patch Of Death. Seems to build fine on Windows
simon authored
103 const char *err;
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
104 Raw raw;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
105
3d88e64 Introduced wrapper macros snew(), snewn() and sresize() for the
simon authored
106 raw = snew(struct raw_backend_data);
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
107 raw->fn = &fn_table;
108 raw->s = NULL;
109 *backend_handle = raw;
110
111 raw->frontend = frontend_handle;
887035a Major destabilisation, phase 1. In this phase I've moved (I think)
simon authored
112
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
113 /*
114 * Try to find host.
115 */
3ad9d39 Robert de Bath's asynchronous-connect patch. Helps a lot in port
simon authored
116 {
57356d6 Robustness fixes for KEXINIT handling and others. In particular, I've
simon authored
117 char *buf;
0558174 Integrate unfix.org's IPv6 patches up to level 10, with rather a lot
simon authored
118 buf = dupprintf("Looking up host \"%s\"%s", host,
119 (cfg->addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
120 (cfg->addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
121 "")));
a832773 Yet more global-removal. The static variables in logging.c are now
simon authored
122 logevent(raw->frontend, buf);
57356d6 Robustness fixes for KEXINIT handling and others. In particular, I've
simon authored
123 sfree(buf);
3ad9d39 Robert de Bath's asynchronous-connect patch. Helps a lot in port
simon authored
124 }
0558174 Integrate unfix.org's IPv6 patches up to level 10, with rather a lot
simon authored
125 addr = name_lookup(host, port, realhost, cfg, cfg->addressfamily);
f85e6f6 Control of 'addr' is now handed over to {platform_,}new_connection() and
jacob authored
126 if ((err = sk_addr_error(addr)) != NULL) {
127 sk_addr_free(addr);
8df7a77 Created a shiny new abstraction for the socket handling. Has many
simon authored
128 return err;
f85e6f6 Control of 'addr' is now handed over to {platform_,}new_connection() and
jacob authored
129 }
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
130
131 if (port < 0)
132 port = 23; /* default telnet port */
133
134 /*
135 * Open socket.
136 */
79bf227 Add a configuration option for TCP keepalives (SO_KEEPALIVE), default…
jacob authored
137 raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
e8fa8f6 proxy.c now no longer refers to `cfg'. Instead, each of the three
simon authored
138 (Plug) raw, cfg);
6f1e7b7 Fix a few stylistic warnings from Apple's C compilers.
ben authored
139 if ((err = sk_socket_error(raw->s)) != NULL)
8df7a77 Created a shiny new abstraction for the socket handling. Has many
simon authored
140 return err;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
141
881da16 Been meaning to do this for years: introduce a configuration option
simon authored
142 if (*cfg->loghost) {
143 char *colon;
144
145 sfree(*realhost);
146 *realhost = dupstr(cfg->loghost);
147 colon = strrchr(*realhost, ':');
148 if (colon) {
149 /*
150 * FIXME: if we ever update this aspect of ssh.c for
151 * IPv6 literal management, this should change in line
152 * with it.
153 */
154 *colon++ = '\0';
155 }
156 }
157
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
158 return NULL;
159 }
160
fabd180 Add the ability to close sessions. This adds *_free() functions to most
ben authored
161 static void raw_free(void *handle)
162 {
163 Raw raw = (Raw) handle;
164
165 if (raw->s)
166 sk_close(raw->s);
167 sfree(raw);
168 }
169
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
170 /*
8691687 The back ends now contain their own copies of the Config structure,
simon authored
171 * Stub routine (we don't have any need to reconfigure this backend).
172 */
173 static void raw_reconfig(void *handle, Config *cfg)
174 {
175 }
176
177 /*
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
178 * Called to send data down the raw connection.
179 */
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
180 static int raw_send(void *handle, char *buf, int len)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
181 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
182 Raw raw = (Raw) handle;
183
184 if (raw->s == NULL)
b5a460c Add a couple of missing return values
simon authored
185 return 0;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
186
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
187 raw->bufsize = sk_write(raw->s, buf, len);
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
188
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
189 return raw->bufsize;
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
190 }
191
192 /*
193 * Called to query the current socket sendability status.
194 */
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
195 static int raw_sendbuffer(void *handle)
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
196 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
197 Raw raw = (Raw) handle;
198 return raw->bufsize;
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
199 }
200
201 /*
202 * Called to set the size of the window
203 */
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
204 static void raw_size(void *handle, int width, int height)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
205 {
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
206 /* Do nothing! */
207 return;
208 }
209
210 /*
211 * Send raw special codes.
212 */
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
213 static void raw_special(void *handle, Telnet_Special code)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
214 {
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
215 /* Do nothing! */
216 return;
217 }
218
125105d Turned the old `Telnet Command' System-submenu into a more general
simon authored
219 /*
220 * Return a list of the special codes that make sense in this
221 * protocol.
222 */
223 static const struct telnet_special *raw_get_specials(void *handle)
224 {
225 return NULL;
226 }
227
6226c93 The `socket' function in the backends is only ever checked to see if
simon authored
228 static int raw_connected(void *handle)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
229 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
230 Raw raw = (Raw) handle;
6226c93 The `socket' function in the backends is only ever checked to see if
simon authored
231 return raw->s != NULL;
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
232 }
8ccc75b Stop plink losing data at start of session
simon authored
233
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
234 static int raw_sendok(void *handle)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
235 {
236 return 1;
237 }
4017be6 Added a fourth application: plink, a command line connection utility
simon authored
238
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
239 static void raw_unthrottle(void *handle, int backlog)
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
240 {
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
241 Raw raw = (Raw) handle;
242 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
243 }
244
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
245 static int raw_ldisc(void *handle, int option)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
246 {
0965bee Rethink the whole line discipline architecture. Instead of having
simon authored
247 if (option == LD_EDIT || option == LD_ECHO)
32874ae Run entire source base through GNU indent to tidy up the varying
simon authored
248 return 1;
0965bee Rethink the whole line discipline architecture. Instead of having
simon authored
249 return 0;
250 }
251
b9d7bca Line discipline module now uses dynamically allocated data. Also
simon authored
252 static void raw_provide_ldisc(void *handle, void *ldisc)
253 {
254 /* This is a stub. */
255 }
256
a832773 Yet more global-removal. The static variables in logging.c are now
simon authored
257 static void raw_provide_logctx(void *handle, void *logctx)
258 {
259 /* This is a stub. */
260 }
261
5147029 Major destabilisation, phase 2. This time it's the backends' turn:
simon authored
262 static int raw_exitcode(void *handle)
d8d6c7e Add a new back-end function to return the exit code of the remote
simon authored
263 {
0da1a79 pterm.c now relies on backend `exitcode' functions returning <0 when
simon authored
264 Raw raw = (Raw) handle;
265 if (raw->s != NULL)
266 return -1; /* still connected */
267 else
268 /* Exit codes are a meaningless concept in the Raw protocol */
269 return 0;
d8d6c7e Add a new back-end function to return the exit code of the remote
simon authored
270 }
271
f89c329 Loose end from r5031: the Kex panel should only be displayed in
simon authored
272 /*
273 * cfg_info for Raw does nothing at all.
274 */
275 static int raw_cfg_info(void *handle)
276 {
277 return 0;
278 }
279
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
280 Backend raw_backend = {
281 raw_init,
fabd180 Add the ability to close sessions. This adds *_free() functions to most
ben authored
282 raw_free,
8691687 The back ends now contain their own copies of the Config structure,
simon authored
283 raw_reconfig,
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
284 raw_send,
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
285 raw_sendbuffer,
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
286 raw_size,
4017be6 Added a fourth application: plink, a command line connection utility
simon authored
287 raw_special,
125105d Turned the old `Telnet Command' System-submenu into a more general
simon authored
288 raw_get_specials,
6226c93 The `socket' function in the backends is only ever checked to see if
simon authored
289 raw_connected,
d8d6c7e Add a new back-end function to return the exit code of the remote
simon authored
290 raw_exitcode,
97db3be Store default port number in each back end
simon authored
291 raw_sendok,
0965bee Rethink the whole line discipline architecture. Instead of having
simon authored
292 raw_ldisc,
b9d7bca Line discipline module now uses dynamically allocated data. Also
simon authored
293 raw_provide_ldisc,
a832773 Yet more global-removal. The static variables in logging.c are now
simon authored
294 raw_provide_logctx,
5471d09 Extensive changes that _should_ fix the socket buffering problems,
simon authored
295 raw_unthrottle,
f89c329 Loose end from r5031: the Kex panel should only be displayed in
simon authored
296 raw_cfg_info,
9e164d8 Rationalise access to, and content of, backends[] array.
jacob authored
297 "raw",
298 PROT_RAW,
a4451dd Implement Marcin Bulandra's suggestion of only automatically updating…
jacob authored
299 0
5e1a8e2 Mark Baker's raw-TCP back end (untested and experimental as yet)
simon authored
300 };
Something went wrong with that request. Please try again.