17 #define RAW_MAX_BACKLOG 4096
\r
19 typedef struct raw_backend_data {
\r
20 const struct plug_function_table *fn;
\r
21 /* the above field _must_ be first in the structure */
\r
28 static void raw_size(void *handle, int width, int height);
\r
30 static void c_write(Raw raw, char *buf, int len)
\r
32 int backlog = from_backend(raw->frontend, 0, buf, len);
\r
33 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
\r
36 static void raw_log(Plug plug, int type, SockAddr addr, int port,
\r
37 const char *error_msg, int error_code)
\r
39 Raw raw = (Raw) plug;
\r
40 char addrbuf[256], *msg;
\r
42 sk_getaddr(addr, addrbuf, lenof(addrbuf));
\r
45 msg = dupprintf("Connecting to %s port %d", addrbuf, port);
\r
47 msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
\r
49 logevent(raw->frontend, msg);
\r
52 static int raw_closing(Plug plug, const char *error_msg, int error_code,
\r
55 Raw raw = (Raw) plug;
\r
60 notify_remote_exit(raw->frontend);
\r
63 /* A socket error has occurred. */
\r
64 logevent(raw->frontend, error_msg);
\r
65 connection_fatal(raw->frontend, "%s", error_msg);
\r
66 } /* Otherwise, the remote side closed the connection normally. */
\r
70 static int raw_receive(Plug plug, int urgent, char *data, int len)
\r
72 Raw raw = (Raw) plug;
\r
73 c_write(raw, data, len);
\r
77 static void raw_sent(Plug plug, int bufsize)
\r
79 Raw raw = (Raw) plug;
\r
80 raw->bufsize = bufsize;
\r
84 * Called to set up the raw connection.
\r
86 * Returns an error message, or NULL on success.
\r
88 * Also places the canonical host name into `realhost'. It must be
\r
89 * freed by the caller.
\r
91 static const char *raw_init(void *frontend_handle, void **backend_handle,
\r
93 char *host, int port, char **realhost, int nodelay,
\r
96 static const struct plug_function_table fn_table = {
\r
106 raw = snew(struct raw_backend_data);
\r
107 raw->fn = &fn_table;
\r
109 *backend_handle = raw;
\r
111 raw->frontend = frontend_handle;
\r
114 * Try to find host.
\r
118 buf = dupprintf("Looking up host \"%s\"%s", host,
\r
119 (cfg->addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
\r
120 (cfg->addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
\r
122 logevent(raw->frontend, buf);
\r
125 addr = name_lookup(host, port, realhost, cfg, cfg->addressfamily);
\r
126 if ((err = sk_addr_error(addr)) != NULL) {
\r
127 sk_addr_free(addr);
\r
132 port = 23; /* default telnet port */
\r
137 raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
\r
139 if ((err = sk_socket_error(raw->s)) != NULL)
\r
142 if (*cfg->loghost) {
\r
146 *realhost = dupstr(cfg->loghost);
\r
147 colon = strrchr(*realhost, ':');
\r
150 * FIXME: if we ever update this aspect of ssh.c for
\r
151 * IPv6 literal management, this should change in line
\r
161 static void raw_free(void *handle)
\r
163 Raw raw = (Raw) handle;
\r
171 * Stub routine (we don't have any need to reconfigure this backend).
\r
173 static void raw_reconfig(void *handle, Config *cfg)
\r
178 * Called to send data down the raw connection.
\r
180 static int raw_send(void *handle, char *buf, int len)
\r
182 Raw raw = (Raw) handle;
\r
184 if (raw->s == NULL)
\r
187 raw->bufsize = sk_write(raw->s, buf, len);
\r
189 return raw->bufsize;
\r
193 * Called to query the current socket sendability status.
\r
195 static int raw_sendbuffer(void *handle)
\r
197 Raw raw = (Raw) handle;
\r
198 return raw->bufsize;
\r
202 * Called to set the size of the window
\r
204 static void raw_size(void *handle, int width, int height)
\r
211 * Send raw special codes.
\r
213 static void raw_special(void *handle, Telnet_Special code)
\r
220 * Return a list of the special codes that make sense in this
\r
223 static const struct telnet_special *raw_get_specials(void *handle)
\r
228 static int raw_connected(void *handle)
\r
230 Raw raw = (Raw) handle;
\r
231 return raw->s != NULL;
\r
234 static int raw_sendok(void *handle)
\r
239 static void raw_unthrottle(void *handle, int backlog)
\r
241 Raw raw = (Raw) handle;
\r
242 sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
\r
245 static int raw_ldisc(void *handle, int option)
\r
247 if (option == LD_EDIT || option == LD_ECHO)
\r
252 static void raw_provide_ldisc(void *handle, void *ldisc)
\r
254 /* This is a stub. */
\r
257 static void raw_provide_logctx(void *handle, void *logctx)
\r
259 /* This is a stub. */
\r
262 static int raw_exitcode(void *handle)
\r
264 Raw raw = (Raw) handle;
\r
265 if (raw->s != NULL)
\r
266 return -1; /* still connected */
\r
268 /* Exit codes are a meaningless concept in the Raw protocol */
\r
273 * cfg_info for Raw does nothing at all.
\r
275 static int raw_cfg_info(void *handle)
\r
280 Backend raw_backend = {
\r
294 raw_provide_logctx,
\r