13 #define RAW_MAX_BACKLOG 4096
15 typedef struct raw_backend_data
{
16 const struct plug_function_table
*fn
;
17 /* the above field _must_ be first in the structure */
24 static void raw_size(void *handle
, int width
, int height
);
26 static void c_write(Raw raw
, char *buf
, int len
)
28 int backlog
= from_backend(raw
->frontend
, 0, buf
, len
);
29 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
32 static void raw_log(Plug plug
, int type
, SockAddr addr
, int port
,
33 const char *error_msg
, int error_code
)
36 char addrbuf
[256], *msg
;
38 sk_getaddr(addr
, addrbuf
, lenof(addrbuf
));
41 msg
= dupprintf("Connecting to %s port %d", addrbuf
, port
);
43 msg
= dupprintf("Failed to connect to %s: %s", addrbuf
, error_msg
);
45 logevent(raw
->frontend
, msg
);
48 static int raw_closing(Plug plug
, const char *error_msg
, int error_code
,
56 notify_remote_exit(raw
->frontend
);
59 /* A socket error has occurred. */
60 logevent(raw
->frontend
, error_msg
);
61 connection_fatal(raw
->frontend
, "%s", error_msg
);
62 } /* Otherwise, the remote side closed the connection normally. */
66 static int raw_receive(Plug plug
, int urgent
, char *data
, int len
)
69 c_write(raw
, data
, len
);
73 static void raw_sent(Plug plug
, int bufsize
)
76 raw
->bufsize
= bufsize
;
80 * Called to set up the raw connection.
82 * Returns an error message, or NULL on success.
84 * Also places the canonical host name into `realhost'. It must be
85 * freed by the caller.
87 static const char *raw_init(void *frontend_handle
, void **backend_handle
,
89 char *host
, int port
, char **realhost
, int nodelay
,
92 static const struct plug_function_table fn_table
= {
102 raw
= snew(struct raw_backend_data
);
105 *backend_handle
= raw
;
107 raw
->frontend
= frontend_handle
;
114 buf
= dupprintf("Looking up host \"%s\"%s", host
,
115 (cfg
->addressfamily
== ADDRTYPE_IPV4 ?
" (IPv4)" :
116 (cfg
->addressfamily
== ADDRTYPE_IPV6 ?
" (IPv6)" :
118 logevent(raw
->frontend
, buf
);
121 addr
= name_lookup(host
, port
, realhost
, cfg
, cfg
->addressfamily
);
122 if ((err
= sk_addr_error(addr
)) != NULL
) {
128 port
= 23; /* default telnet port */
133 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, keepalive
,
135 if ((err
= sk_socket_error(raw
->s
)) != NULL
)
141 static void raw_free(void *handle
)
143 Raw raw
= (Raw
) handle
;
151 * Stub routine (we don't have any need to reconfigure this backend).
153 static void raw_reconfig(void *handle
, Config
*cfg
)
158 * Called to send data down the raw connection.
160 static int raw_send(void *handle
, char *buf
, int len
)
162 Raw raw
= (Raw
) handle
;
167 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
173 * Called to query the current socket sendability status.
175 static int raw_sendbuffer(void *handle
)
177 Raw raw
= (Raw
) handle
;
182 * Called to set the size of the window
184 static void raw_size(void *handle
, int width
, int height
)
191 * Send raw special codes.
193 static void raw_special(void *handle
, Telnet_Special code
)
200 * Return a list of the special codes that make sense in this
203 static const struct telnet_special
*raw_get_specials(void *handle
)
208 static Socket
raw_socket(void *handle
)
210 Raw raw
= (Raw
) handle
;
214 static int raw_sendok(void *handle
)
219 static void raw_unthrottle(void *handle
, int backlog
)
221 Raw raw
= (Raw
) handle
;
222 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
225 static int raw_ldisc(void *handle
, int option
)
227 if (option
== LD_EDIT
|| option
== LD_ECHO
)
232 static void raw_provide_ldisc(void *handle
, void *ldisc
)
234 /* This is a stub. */
237 static void raw_provide_logctx(void *handle
, void *logctx
)
239 /* This is a stub. */
242 static int raw_exitcode(void *handle
)
244 Raw raw
= (Raw
) handle
;
246 return -1; /* still connected */
248 /* Exit codes are a meaningless concept in the Raw protocol */
253 * cfg_info for Raw does nothing at all.
255 static int raw_cfg_info(void *handle
)
260 Backend raw_backend
= {