17 #define RAW_MAX_BACKLOG 4096
19 typedef struct raw_backend_data
{
20 const struct plug_function_table
*fn
;
21 /* the above field _must_ be first in the structure */
28 static void raw_size(void *handle
, int width
, int height
);
30 static void c_write(Raw raw
, char *buf
, int len
)
32 int backlog
= from_backend(raw
->frontend
, 0, buf
, len
);
33 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
36 static void raw_log(Plug plug
, int type
, SockAddr addr
, int port
,
37 const char *error_msg
, int error_code
)
40 char addrbuf
[256], *msg
;
42 sk_getaddr(addr
, addrbuf
, lenof(addrbuf
));
45 msg
= dupprintf("Connecting to %s port %d", addrbuf
, port
);
47 msg
= dupprintf("Failed to connect to %s: %s", addrbuf
, error_msg
);
49 logevent(raw
->frontend
, msg
);
52 static int raw_closing(Plug plug
, const char *error_msg
, int error_code
,
60 notify_remote_exit(raw
->frontend
);
63 /* A socket error has occurred. */
64 logevent(raw
->frontend
, error_msg
);
65 connection_fatal(raw
->frontend
, "%s", error_msg
);
66 } /* Otherwise, the remote side closed the connection normally. */
70 static int raw_receive(Plug plug
, int urgent
, char *data
, int len
)
73 c_write(raw
, data
, len
);
77 static void raw_sent(Plug plug
, int bufsize
)
80 raw
->bufsize
= bufsize
;
84 * Called to set up the raw connection.
86 * Returns an error message, or NULL on success.
88 * Also places the canonical host name into `realhost'. It must be
89 * freed by the caller.
91 static const char *raw_init(void *frontend_handle
, void **backend_handle
,
93 char *host
, int port
, char **realhost
, int nodelay
,
96 static const struct plug_function_table fn_table
= {
106 raw
= snew(struct raw_backend_data
);
109 *backend_handle
= raw
;
111 raw
->frontend
= frontend_handle
;
118 buf
= dupprintf("Looking up host \"%s\"%s", host
,
119 (cfg
->addressfamily
== ADDRTYPE_IPV4 ?
" (IPv4)" :
120 (cfg
->addressfamily
== ADDRTYPE_IPV6 ?
" (IPv6)" :
122 logevent(raw
->frontend
, buf
);
125 addr
= name_lookup(host
, port
, realhost
, cfg
, cfg
->addressfamily
);
126 if ((err
= sk_addr_error(addr
)) != NULL
) {
132 port
= 23; /* default telnet port */
137 raw
->s
= new_connection(addr
, *realhost
, port
, 0, 1, nodelay
, keepalive
,
139 if ((err
= sk_socket_error(raw
->s
)) != NULL
)
145 static void raw_free(void *handle
)
147 Raw raw
= (Raw
) handle
;
155 * Stub routine (we don't have any need to reconfigure this backend).
157 static void raw_reconfig(void *handle
, Config
*cfg
)
162 * Called to send data down the raw connection.
164 static int raw_send(void *handle
, char *buf
, int len
)
166 Raw raw
= (Raw
) handle
;
171 raw
->bufsize
= sk_write(raw
->s
, buf
, len
);
177 * Called to query the current socket sendability status.
179 static int raw_sendbuffer(void *handle
)
181 Raw raw
= (Raw
) handle
;
186 * Called to set the size of the window
188 static void raw_size(void *handle
, int width
, int height
)
195 * Send raw special codes.
197 static void raw_special(void *handle
, Telnet_Special code
)
204 * Return a list of the special codes that make sense in this
207 static const struct telnet_special
*raw_get_specials(void *handle
)
212 static Socket
raw_socket(void *handle
)
214 Raw raw
= (Raw
) handle
;
218 static int raw_sendok(void *handle
)
223 static void raw_unthrottle(void *handle
, int backlog
)
225 Raw raw
= (Raw
) handle
;
226 sk_set_frozen(raw
->s
, backlog
> RAW_MAX_BACKLOG
);
229 static int raw_ldisc(void *handle
, int option
)
231 if (option
== LD_EDIT
|| option
== LD_ECHO
)
236 static void raw_provide_ldisc(void *handle
, void *ldisc
)
238 /* This is a stub. */
241 static void raw_provide_logctx(void *handle
, void *logctx
)
243 /* This is a stub. */
246 static int raw_exitcode(void *handle
)
248 Raw raw
= (Raw
) handle
;
250 return -1; /* still connected */
252 /* Exit codes are a meaningless concept in the Raw protocol */
257 * cfg_info for Raw does nothing at all.
259 static int raw_cfg_info(void *handle
)
264 Backend raw_backend
= {