1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

Move other backends into a subdirectory.

This is the last of the subdirectory creations I had planned. This one
is almost too footling to bother with (it hardly declutters the top
level very much).

One useful side effect is that I've included testback.c (containing
the null and loopback backends) in the otherbackends library, which
means it will now actually be _compiled_ even when nothing's using it,
and we'll spot bit-rot promptly when internal APIs change.

(And, to prove the point, I've immediately had to fix some bit-rot.)
This commit is contained in:
Simon Tatham
2021-04-22 18:17:35 +01:00
parent 8f0f5b69c0
commit 419e5e2230
7 changed files with 16 additions and 10 deletions

View File

@ -0,0 +1,6 @@
add_sources_from_current_dir(otherbackends
raw.c
rlogin.c
supdup.c
telnet.c
testback.c)

330
otherbackends/raw.c Normal file
View File

@ -0,0 +1,330 @@
/*
* "Raw" backend.
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "putty.h"
#define RAW_MAX_BACKLOG 4096
typedef struct Raw Raw;
struct Raw {
Socket *s;
bool closed_on_socket_error;
size_t bufsize;
Seat *seat;
LogContext *logctx;
bool sent_console_eof, sent_socket_eof, session_started;
Conf *conf;
Plug plug;
Backend backend;
};
static void raw_size(Backend *be, int width, int height);
static void c_write(Raw *raw, const void *buf, size_t len)
{
size_t backlog = seat_stdout(raw->seat, buf, len);
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
}
static void raw_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code)
{
Raw *raw = container_of(plug, Raw, plug);
backend_socket_log(raw->seat, raw->logctx, type, addr, port,
error_msg, error_code, raw->conf, raw->session_started);
}
static void raw_check_close(Raw *raw)
{
/*
* Called after we send EOF on either the socket or the console.
* Its job is to wind up the session once we have sent EOF on both.
*/
if (raw->sent_console_eof && raw->sent_socket_eof) {
if (raw->s) {
sk_close(raw->s);
raw->s = NULL;
seat_notify_remote_exit(raw->seat);
}
}
}
static void raw_closing(Plug *plug, const char *error_msg, int error_code,
bool calling_back)
{
Raw *raw = container_of(plug, Raw, plug);
if (error_msg) {
/* A socket error has occurred. */
if (raw->s) {
sk_close(raw->s);
raw->s = NULL;
raw->closed_on_socket_error = true;
seat_notify_remote_exit(raw->seat);
}
logevent(raw->logctx, error_msg);
seat_connection_fatal(raw->seat, "%s", error_msg);
} else {
/* Otherwise, the remote side closed the connection normally. */
if (!raw->sent_console_eof && seat_eof(raw->seat)) {
/*
* The front end wants us to close the outgoing side of the
* connection as soon as we see EOF from the far end.
*/
if (!raw->sent_socket_eof) {
if (raw->s)
sk_write_eof(raw->s);
raw->sent_socket_eof= true;
}
}
raw->sent_console_eof = true;
raw_check_close(raw);
}
}
static void raw_receive(Plug *plug, int urgent, const char *data, size_t len)
{
Raw *raw = container_of(plug, Raw, plug);
c_write(raw, data, len);
/* We count 'session start', for proxy logging purposes, as being
* when data is received from the network and printed. */
raw->session_started = true;
}
static void raw_sent(Plug *plug, size_t bufsize)
{
Raw *raw = container_of(plug, Raw, plug);
raw->bufsize = bufsize;
}
static const PlugVtable Raw_plugvt = {
.log = raw_log,
.closing = raw_closing,
.receive = raw_receive,
.sent = raw_sent,
};
/*
* Called to set up the raw connection.
*
* Returns an error message, or NULL on success.
*
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static char *raw_init(const BackendVtable *vt, Seat *seat,
Backend **backend_handle, LogContext *logctx,
Conf *conf, const char *host, int port,
char **realhost, bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
Raw *raw;
int addressfamily;
char *loghost;
/* No local authentication phase in this protocol */
seat_set_trust_status(seat, false);
raw = snew(Raw);
raw->plug.vt = &Raw_plugvt;
raw->backend.vt = vt;
raw->s = NULL;
raw->closed_on_socket_error = false;
*backend_handle = &raw->backend;
raw->sent_console_eof = raw->sent_socket_eof = false;
raw->bufsize = 0;
raw->session_started = false;
raw->conf = conf_copy(conf);
raw->seat = seat;
raw->logctx = logctx;
addressfamily = conf_get_int(conf, CONF_addressfamily);
/*
* Try to find host.
*/
addr = name_lookup(host, port, realhost, conf, addressfamily,
raw->logctx, "main connection");
if ((err = sk_addr_error(addr)) != NULL) {
sk_addr_free(addr);
return dupstr(err);
}
if (port < 0)
port = 23; /* default telnet port */
/*
* Open socket.
*/
raw->s = new_connection(addr, *realhost, port, false, true, nodelay,
keepalive, &raw->plug, conf);
if ((err = sk_socket_error(raw->s)) != NULL)
return dupstr(err);
loghost = conf_get_str(conf, CONF_loghost);
if (*loghost) {
char *colon;
sfree(*realhost);
*realhost = dupstr(loghost);
colon = host_strrchr(*realhost, ':');
if (colon)
*colon++ = '\0';
}
return NULL;
}
static void raw_free(Backend *be)
{
Raw *raw = container_of(be, Raw, backend);
if (raw->s)
sk_close(raw->s);
conf_free(raw->conf);
sfree(raw);
}
/*
* Stub routine (we don't have any need to reconfigure this backend).
*/
static void raw_reconfig(Backend *be, Conf *conf)
{
}
/*
* Called to send data down the raw connection.
*/
static size_t raw_send(Backend *be, const char *buf, size_t len)
{
Raw *raw = container_of(be, Raw, backend);
if (raw->s == NULL)
return 0;
raw->bufsize = sk_write(raw->s, buf, len);
return raw->bufsize;
}
/*
* Called to query the current socket sendability status.
*/
static size_t raw_sendbuffer(Backend *be)
{
Raw *raw = container_of(be, Raw, backend);
return raw->bufsize;
}
/*
* Called to set the size of the window
*/
static void raw_size(Backend *be, int width, int height)
{
/* Do nothing! */
return;
}
/*
* Send raw special codes. We only handle outgoing EOF here.
*/
static void raw_special(Backend *be, SessionSpecialCode code, int arg)
{
Raw *raw = container_of(be, Raw, backend);
if (code == SS_EOF && raw->s) {
sk_write_eof(raw->s);
raw->sent_socket_eof= true;
raw_check_close(raw);
}
return;
}
/*
* Return a list of the special codes that make sense in this
* protocol.
*/
static const SessionSpecial *raw_get_specials(Backend *be)
{
return NULL;
}
static bool raw_connected(Backend *be)
{
Raw *raw = container_of(be, Raw, backend);
return raw->s != NULL;
}
static bool raw_sendok(Backend *be)
{
return true;
}
static void raw_unthrottle(Backend *be, size_t backlog)
{
Raw *raw = container_of(be, Raw, backend);
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
}
static bool raw_ldisc(Backend *be, int option)
{
if (option == LD_EDIT || option == LD_ECHO)
return true;
return false;
}
static void raw_provide_ldisc(Backend *be, Ldisc *ldisc)
{
/* This is a stub. */
}
static int raw_exitcode(Backend *be)
{
Raw *raw = container_of(be, Raw, backend);
if (raw->s != NULL)
return -1; /* still connected */
else if (raw->closed_on_socket_error)
return INT_MAX; /* a socket error counts as an unclean exit */
else
/* Exit codes are a meaningless concept in the Raw protocol */
return 0;
}
/*
* cfg_info for Raw does nothing at all.
*/
static int raw_cfg_info(Backend *be)
{
return 0;
}
const BackendVtable raw_backend = {
.init = raw_init,
.free = raw_free,
.reconfig = raw_reconfig,
.send = raw_send,
.sendbuffer = raw_sendbuffer,
.size = raw_size,
.special = raw_special,
.get_specials = raw_get_specials,
.connected = raw_connected,
.exitcode = raw_exitcode,
.sendok = raw_sendok,
.ldisc_option_state = raw_ldisc,
.provide_ldisc = raw_provide_ldisc,
.unthrottle = raw_unthrottle,
.cfg_info = raw_cfg_info,
.id = "raw",
.displayname = "Raw",
.protocol = PROT_RAW,
.default_port = 0,
};

428
otherbackends/rlogin.c Normal file
View File

@ -0,0 +1,428 @@
/*
* Rlogin backend.
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include "putty.h"
#define RLOGIN_MAX_BACKLOG 4096
typedef struct Rlogin Rlogin;
struct Rlogin {
Socket *s;
bool closed_on_socket_error;
int bufsize;
bool firstbyte;
bool cansize;
int term_width, term_height;
Seat *seat;
LogContext *logctx;
Conf *conf;
/* In case we need to read a username from the terminal before starting */
prompts_t *prompt;
Plug plug;
Backend backend;
};
static void c_write(Rlogin *rlogin, const void *buf, size_t len)
{
size_t backlog = seat_stdout(rlogin->seat, buf, len);
sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG);
}
static void rlogin_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
backend_socket_log(rlogin->seat, rlogin->logctx, type, addr, port,
error_msg, error_code,
rlogin->conf, !rlogin->firstbyte);
}
static void rlogin_closing(Plug *plug, const char *error_msg, int error_code,
bool calling_back)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
/*
* We don't implement independent EOF in each direction for Telnet
* connections; as soon as we get word that the remote side has
* sent us EOF, we wind up the whole connection.
*/
if (rlogin->s) {
sk_close(rlogin->s);
rlogin->s = NULL;
if (error_msg)
rlogin->closed_on_socket_error = true;
seat_notify_remote_exit(rlogin->seat);
}
if (error_msg) {
/* A socket error has occurred. */
logevent(rlogin->logctx, error_msg);
seat_connection_fatal(rlogin->seat, "%s", error_msg);
} /* Otherwise, the remote side closed the connection normally. */
}
static void rlogin_receive(
Plug *plug, int urgent, const char *data, size_t len)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
if (len == 0)
return;
if (urgent == 2) {
char c;
c = *data++;
len--;
if (c == '\x80') {
rlogin->cansize = true;
backend_size(&rlogin->backend,
rlogin->term_width, rlogin->term_height);
}
/*
* We should flush everything (aka Telnet SYNCH) if we see
* 0x02, and we should turn off and on _local_ flow control
* on 0x10 and 0x20 respectively. I'm not convinced it's
* worth it...
*/
} else {
/*
* Main rlogin protocol. This is really simple: the first
* byte is expected to be NULL and is ignored, and the rest
* is printed.
*/
if (rlogin->firstbyte) {
if (data[0] == '\0') {
data++;
len--;
}
rlogin->firstbyte = false;
}
if (len > 0)
c_write(rlogin, data, len);
}
}
static void rlogin_sent(Plug *plug, size_t bufsize)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
rlogin->bufsize = bufsize;
}
static void rlogin_startup(Rlogin *rlogin, const char *ruser)
{
char z = 0;
char *p;
sk_write(rlogin->s, &z, 1);
p = conf_get_str(rlogin->conf, CONF_localusername);
sk_write(rlogin->s, p, strlen(p));
sk_write(rlogin->s, &z, 1);
sk_write(rlogin->s, ruser, strlen(ruser));
sk_write(rlogin->s, &z, 1);
p = conf_get_str(rlogin->conf, CONF_termtype);
sk_write(rlogin->s, p, strlen(p));
sk_write(rlogin->s, "/", 1);
p = conf_get_str(rlogin->conf, CONF_termspeed);
sk_write(rlogin->s, p, strspn(p, "0123456789"));
rlogin->bufsize = sk_write(rlogin->s, &z, 1);
rlogin->prompt = NULL;
}
static const PlugVtable Rlogin_plugvt = {
.log = rlogin_log,
.closing = rlogin_closing,
.receive = rlogin_receive,
.sent = rlogin_sent,
};
/*
* Called to set up the rlogin connection.
*
* Returns an error message, or NULL on success.
*
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static char *rlogin_init(const BackendVtable *vt, Seat *seat,
Backend **backend_handle, LogContext *logctx,
Conf *conf, const char *host, int port,
char **realhost, bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
Rlogin *rlogin;
char *ruser;
int addressfamily;
char *loghost;
rlogin = snew(Rlogin);
rlogin->plug.vt = &Rlogin_plugvt;
rlogin->backend.vt = vt;
rlogin->s = NULL;
rlogin->closed_on_socket_error = false;
rlogin->seat = seat;
rlogin->logctx = logctx;
rlogin->term_width = conf_get_int(conf, CONF_width);
rlogin->term_height = conf_get_int(conf, CONF_height);
rlogin->firstbyte = true;
rlogin->cansize = false;
rlogin->prompt = NULL;
rlogin->conf = conf_copy(conf);
*backend_handle = &rlogin->backend;
addressfamily = conf_get_int(conf, CONF_addressfamily);
/*
* Try to find host.
*/
addr = name_lookup(host, port, realhost, conf, addressfamily,
rlogin->logctx, "rlogin connection");
if ((err = sk_addr_error(addr)) != NULL) {
sk_addr_free(addr);
return dupstr(err);
}
if (port < 0)
port = 513; /* default rlogin port */
/*
* Open socket.
*/
rlogin->s = new_connection(addr, *realhost, port, true, false,
nodelay, keepalive, &rlogin->plug, conf);
if ((err = sk_socket_error(rlogin->s)) != NULL)
return dupstr(err);
loghost = conf_get_str(conf, CONF_loghost);
if (*loghost) {
char *colon;
sfree(*realhost);
*realhost = dupstr(loghost);
colon = host_strrchr(*realhost, ':');
if (colon)
*colon++ = '\0';
}
/*
* Send local username, remote username, terminal type and
* terminal speed - unless we don't have the remote username yet,
* in which case we prompt for it and may end up deferring doing
* anything else until the local prompt mechanism returns.
*/
if ((ruser = get_remote_username(conf)) != NULL) {
/* Next terminal output will come from server */
seat_set_trust_status(rlogin->seat, false);
rlogin_startup(rlogin, ruser);
sfree(ruser);
} else {
int ret;
rlogin->prompt = new_prompts();
rlogin->prompt->to_server = true;
rlogin->prompt->from_server = false;
rlogin->prompt->name = dupstr("Rlogin login name");
add_prompt(rlogin->prompt, dupstr("rlogin username: "), true);
ret = seat_get_userpass_input(rlogin->seat, rlogin->prompt, NULL);
if (ret >= 0) {
/* Next terminal output will come from server */
seat_set_trust_status(rlogin->seat, false);
rlogin_startup(rlogin, prompt_get_result_ref(
rlogin->prompt->prompts[0]));
}
}
return NULL;
}
static void rlogin_free(Backend *be)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
if (rlogin->prompt)
free_prompts(rlogin->prompt);
if (rlogin->s)
sk_close(rlogin->s);
conf_free(rlogin->conf);
sfree(rlogin);
}
/*
* Stub routine (we don't have any need to reconfigure this backend).
*/
static void rlogin_reconfig(Backend *be, Conf *conf)
{
}
/*
* Called to send data down the rlogin connection.
*/
static size_t rlogin_send(Backend *be, const char *buf, size_t len)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
bufchain bc;
if (rlogin->s == NULL)
return 0;
bufchain_init(&bc);
bufchain_add(&bc, buf, len);
if (rlogin->prompt) {
/*
* We're still prompting for a username, and aren't talking
* directly to the network connection yet.
*/
int ret = seat_get_userpass_input(rlogin->seat, rlogin->prompt, &bc);
if (ret >= 0) {
/* Next terminal output will come from server */
seat_set_trust_status(rlogin->seat, false);
rlogin_startup(rlogin, prompt_get_result_ref(
rlogin->prompt->prompts[0]));
/* that nulls out rlogin->prompt, so then we'll start sending
* data down the wire in the obvious way */
}
}
if (!rlogin->prompt) {
while (bufchain_size(&bc) > 0) {
ptrlen data = bufchain_prefix(&bc);
rlogin->bufsize = sk_write(rlogin->s, data.ptr, data.len);
bufchain_consume(&bc, len);
}
}
bufchain_clear(&bc);
return rlogin->bufsize;
}
/*
* Called to query the current socket sendability status.
*/
static size_t rlogin_sendbuffer(Backend *be)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
return rlogin->bufsize;
}
/*
* Called to set the size of the window
*/
static void rlogin_size(Backend *be, int width, int height)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
char b[12] = { '\xFF', '\xFF', 0x73, 0x73, 0, 0, 0, 0, 0, 0, 0, 0 };
rlogin->term_width = width;
rlogin->term_height = height;
if (rlogin->s == NULL || !rlogin->cansize)
return;
b[6] = rlogin->term_width >> 8;
b[7] = rlogin->term_width & 0xFF;
b[4] = rlogin->term_height >> 8;
b[5] = rlogin->term_height & 0xFF;
rlogin->bufsize = sk_write(rlogin->s, b, 12);
return;
}
/*
* Send rlogin special codes.
*/
static void rlogin_special(Backend *be, SessionSpecialCode code, int arg)
{
/* Do nothing! */
return;
}
/*
* Return a list of the special codes that make sense in this
* protocol.
*/
static const SessionSpecial *rlogin_get_specials(Backend *be)
{
return NULL;
}
static bool rlogin_connected(Backend *be)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
return rlogin->s != NULL;
}
static bool rlogin_sendok(Backend *be)
{
/* Rlogin *rlogin = container_of(be, Rlogin, backend); */
return true;
}
static void rlogin_unthrottle(Backend *be, size_t backlog)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG);
}
static bool rlogin_ldisc(Backend *be, int option)
{
/* Rlogin *rlogin = container_of(be, Rlogin, backend); */
return false;
}
static void rlogin_provide_ldisc(Backend *be, Ldisc *ldisc)
{
/* This is a stub. */
}
static int rlogin_exitcode(Backend *be)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
if (rlogin->s != NULL)
return -1; /* still connected */
else if (rlogin->closed_on_socket_error)
return INT_MAX; /* a socket error counts as an unclean exit */
else
/* If we ever implement RSH, we'll probably need to do this properly */
return 0;
}
/*
* cfg_info for rlogin does nothing at all.
*/
static int rlogin_cfg_info(Backend *be)
{
return 0;
}
const BackendVtable rlogin_backend = {
.init = rlogin_init,
.free = rlogin_free,
.reconfig = rlogin_reconfig,
.send = rlogin_send,
.sendbuffer = rlogin_sendbuffer,
.size = rlogin_size,
.special = rlogin_special,
.get_specials = rlogin_get_specials,
.connected = rlogin_connected,
.exitcode = rlogin_exitcode,
.sendok = rlogin_sendok,
.ldisc_option_state = rlogin_ldisc,
.provide_ldisc = rlogin_provide_ldisc,
.unthrottle = rlogin_unthrottle,
.cfg_info = rlogin_cfg_info,
.id = "rlogin",
.displayname = "Rlogin",
.protocol = PROT_RLOGIN,
.default_port = 513,
};

923
otherbackends/supdup.c Normal file
View File

@ -0,0 +1,923 @@
/*
* Supdup backend
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "putty.h"
/*
* TTYOPT FUNCTION BITS (36-bit bitmasks)
*/
#define TOALT 0200000000000LL // Characters 0175 and 0176 are converted to altmode (0033) on input
#define TOCLC 0100000000000LL // (user option bit) Convert lower-case input to upper-case
#define TOERS 0040000000000LL // Selective erase is supported
#define TOMVB 0010000000000LL // Backspacing is supported
#define TOSAI 0004000000000LL // Stanford/ITS extended ASCII graphics character set is supported
#define TOSA1 0002000000000LL // (user option bit) Characters 0001-0037 displayed using Stanford/ITS chars
#define TOOVR 0001000000000LL // Overprinting is supported
#define TOMVU 0000400000000LL // Moving cursor upwards is supported
#define TOMOR 0000200000000LL // (user option bit) System should provide **MORE** processing
#define TOROL 0000100000000LL // (user option bit) Terminal should scroll instead of wrapping
#define TOLWR 0000020000000LL // Lowercase characters are supported
#define TOFCI 0000010000000LL // Terminal can generate CONTROL and META characters
#define TOLID 0000002000000LL // Line insert/delete operations supported
#define TOCID 0000001000000LL // Character insert/delete operations supported
#define TPCBS 0000000000040LL // Terminal is using the "intelligent terminal protocol" (must be on)
#define TPORS 0000000000010LL // Server should process output resets
// Initialization words (36-bit constants)
#define WORDS 0777773000000 // Negative number of config words to send (6) in high 18 bits
#define TCTYP 0000000000007 // Defines the terminal type (MUST be 7)
#define TTYROL 0000000000001 // Scroll amount for terminal (1 line at a time)
// %TD opcodes
//
#define TDMOV 0200 // Cursor positioning
#define TDMV1 0201 // Internal cursor positioning
#define TDEOF 0202 // Erase to end of screen
#define TDEOL 0203 // Erase to end of line
#define TDDLF 0204 // Clear the character the cursor is on
#define TDCRL 0207 // Carriage return
#define TDNOP 0210 // No-op; should be ignored.
#define TDBS 0211 // Backspace (not in official SUPDUP spec)
#define TDLF 0212 // Linefeed (not in official SUPDUP spec)
#define TDCR 0213 // Carriage Return (ditto)
#define TDORS 0214 // Output reset
#define TDQOT 0215 // Quotes the following character
#define TDFS 0216 // Non-destructive forward space
#define TDMV0 0217 // General cursor positioning code
#define TDCLR 0220 // Erase the screen, home cursor
#define TDBEL 0221 // Generate an audio tone, bell, whatever
#define TDILP 0223 // Insert blank lines at the cursor
#define TDDLP 0224 // Delete lines at the cursor
#define TDICP 0225 // Insert blanks at cursor
#define TDDCP 0226 // Delete characters at cursor
#define TDBOW 0227 // Display black chars on white screen
#define TDRST 0230 // Reset %TDBOW
/* Maximum number of octets following a %TD code. */
#define TD_ARGS_MAX 4
typedef struct supdup_tag Supdup;
struct supdup_tag
{
Socket *s;
bool closed_on_socket_error;
Seat *seat;
LogContext *logctx;
int term_width, term_height;
long long ttyopt;
long tcmxv;
long tcmxh;
bool sent_location;
Conf *conf;
int bufsize;
enum {
CONNECTING, // waiting for %TDNOP from server after sending connection params
CONNECTED // %TDNOP received, connected.
} state;
enum {
TD_TOPLEVEL,
TD_ARGS,
TD_ARGSDONE
} tdstate;
int td_code;
int td_argcount;
char td_args[TD_ARGS_MAX];
int td_argindex;
void (*print) (strbuf *outbuf, int c);
Pinger *pinger;
Plug plug;
Backend backend;
};
#define SUPDUP_MAX_BACKLOG 4096
static void c_write(Supdup *supdup, unsigned char *buf, int len)
{
size_t backlog = seat_stdout(supdup->seat, buf, len);
sk_set_frozen(supdup->s, backlog > SUPDUP_MAX_BACKLOG);
}
static void supdup_send_location(Supdup *supdup)
{
char locHeader[] = { 0300, 0302 };
char* locString = conf_get_str(supdup->conf, CONF_supdup_location);
sk_write(supdup->s, locHeader, sizeof(locHeader));
sk_write(supdup->s, locString, strlen(locString) + 1); // include NULL terminator
}
static void print_ascii(strbuf *outbuf, int c)
{
/* In ASCII mode, ignore control characters. The server shouldn't
send them. */
if (c >= 040 && c < 0177)
put_byte (outbuf, c);
}
static void print_its(strbuf *outbuf, int c)
{
/* The ITS character set is documented in RFC 734. */
static const char *map[] = {
"\xc2\xb7", "\342\206\223", "\316\261", "\316\262",
"\342\210\247", "\302\254", "\316\265", "\317\200",
"\316\273", "\xce\xb3", "\xce\xb4", "\xe2\x86\x91",
"\xc2\xb1", "\xe2\x8a\x95", "\342\210\236", "\342\210\202",
"\342\212\202", "\342\212\203", "\342\210\251", "\342\210\252",
"\342\210\200", "\342\210\203", "\xe2\x8a\x97", "\342\206\224",
"\xe2\x86\x90", "\342\206\222", "\xe2\x89\xa0", "\xe2\x97\x8a",
"\342\211\244", "\342\211\245", "\342\211\241", "\342\210\250",
" ", "!", "\"", "#", "$", "%", "&", "'",
"(", ")", "*", "+", ",", "-", ".", "/",
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", ":", ";", "<", "=", ">", "?",
"@", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "[", "\\", "]", "^", "_",
"`", "a", "b", "c", "d", "e", "f", "g",
"h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z", "{", "|", "}", "~", "\xe2\x88\xab"
};
put_data (outbuf, map[c], strlen(map[c]));
}
static void print_waits(strbuf *outbuf, int c)
{
/* The WAITS character set used at the Stanford AI Lab is documented
here: https://www.saildart.org/allow/sail-charset-utf8.html */
static const char *map[] = {
"", "\342\206\223", "\316\261", "\316\262",
"\342\210\247", "\302\254", "\316\265", "\317\200",
"\316\273", "", "", "",
"", "", "\342\210\236", "\342\210\202",
"\342\212\202", "\342\212\203", "\342\210\251", "\342\210\252",
"\342\210\200", "\342\210\203", "\xe2\x8a\x97", "\342\206\224",
"_", "\342\206\222", "~", "\xe2\x89\xa0",
"\342\211\244", "\342\211\245", "\342\211\241", "\342\210\250",
" ", "!", "\"", "#", "$", "%", "&", "'",
"(", ")", "*", "+", ",", "-", ".", "/",
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", ":", ";", "<", "=", ">", "?",
"@", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T", "U", "V", "W",
"X", "Y", "Z", "[", "\\", "]", "\xe2\x86\x91", "\xe2\x86\x90",
"`", "a", "b", "c", "d", "e", "f", "g",
"h", "i", "j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v", "w",
"x", "y", "z", "{", "|", "\xe2\x97\x8a", "}", ""
};
put_data (outbuf, map[c], strlen(map[c]));
}
static void do_toplevel(Supdup *supdup, strbuf *outbuf, int c)
{
// Toplevel: Waiting for a %TD code or a printable character
if (c >= 0200) {
// Handle SUPDUP %TD codes (codes greater than or equal to 200)
supdup->td_argindex = 0;
supdup->td_code = c;
switch (c) {
case TDMOV:
// %TD codes using 4 arguments
supdup->td_argcount = 4;
supdup->tdstate = TD_ARGS;
break;
case TDMV0:
case TDMV1:
// %TD codes using 2 arguments
supdup->td_argcount = 2;
supdup->tdstate = TD_ARGS;
break;
case TDQOT:
case TDILP:
case TDDLP:
case TDICP:
case TDDCP:
// %TD codes using 1 argument
supdup->td_argcount = 1;
supdup->tdstate = TD_ARGS;
break;
case TDEOF:
case TDEOL:
case TDDLF:
case TDCRL:
case TDNOP:
case TDORS:
case TDFS:
case TDCLR:
case TDBEL:
case TDBOW:
case TDRST:
case TDBS:
case TDCR:
case TDLF:
// %TD codes using 0 arguments
supdup->td_argcount = 0;
supdup->tdstate = TD_ARGSDONE;
break;
default:
// Unhandled, ignore
break;
}
} else {
supdup->print(outbuf, c);
}
}
static void do_args(Supdup *supdup, strbuf *outbuf, int c)
{
// Collect up args for %TD code
if (supdup->td_argindex < TD_ARGS_MAX) {
supdup->td_args[supdup->td_argindex] = c;
supdup->td_argindex++;
if (supdup->td_argcount == supdup->td_argindex) {
// No more args, %TD code is ready to go.
supdup->tdstate = TD_ARGSDONE;
}
} else {
// Should never hit this state, if we do we will just
// return to TOPLEVEL.
supdup->tdstate = TD_TOPLEVEL;
}
}
static void do_argsdone(Supdup *supdup, strbuf *outbuf, int c)
{
char buf[4];
int x, y;
// Arguments for %TD code have been collected; dispatch based
// on the %TD code we're handling.
switch (supdup->td_code) {
case TDMOV:
/*
General cursor position code. Followed by four bytes;
the first two are the "old" vertical and horizontal
positions and may be ignored. The next two are the new
vertical and horizontal positions. The cursor should be
moved to this position.
*/
// We only care about the new position.
strbuf_catf(outbuf, "\033[%d;%dH", supdup->td_args[2]+1, supdup->td_args[3]+1);
break;
case TDMV0:
case TDMV1:
/*
General cursor position code. Followed by two bytes;
the new vertical and horizontal positions.
*/
strbuf_catf(outbuf, "\033[%d;%dH", supdup->td_args[0]+1, supdup->td_args[1]+1);
break;
case TDEOF:
/*
Erase to end of screen. This is an optional function
since many terminals do not support this. If the
terminal does not support this function, it should be
treated the same as %TDEOL.
%TDEOF does an erase to end of line, then erases all
lines lower on the screen than the cursor. The cursor
does not move.
*/
strbuf_catf(outbuf, "\033[J");
break;
case TDEOL:
/*
Erase to end of line. This erases the character
position the cursor is at and all positions to the right
on the same line. The cursor does not move.
*/
strbuf_catf(outbuf, "\033[K");
break;
case TDDLF:
/*
Clear the character position the cursor is on. The
cursor does not move.
*/
strbuf_catf(outbuf, "\033[X");
break;
case TDCRL:
/*
If the cursor is not on the bottom line of the screen,
move cursor to the beginning of the next line and clear
that line. If the cursor is at the bottom line, scroll
up.
*/
strbuf_catf(outbuf, "\015\012");
break;
case TDNOP:
/*
No-op; should be ignored.
*/
break;
case TDORS:
/*
Output reset. This code serves as a data mark for
aborting output much as IAC DM does in the ordinary
TELNET protocol.
*/
outbuf->len = 0;
if (!seat_get_cursor_position(supdup->seat, &x, &y))
x = y = 0;
buf[0] = 034;
buf[1] = 020;
buf[2] = y;
buf[3] = x;
sk_write(supdup->s, buf, 4);
break;
case TDQOT:
/*
Quotes the following character. This is used when
sending 8-bit codes which are not %TD codes, for
instance when loading programs into an intelligent
terminal. The following character should be passed
through intact to the terminal.
*/
put_byte(outbuf, supdup->td_args[0]);
break;
case TDFS:
/*
Non-destructive forward space. The cursor moves right
one position; this code will not be sent at the end of a
line.
*/
strbuf_catf(outbuf, "\033[C");
break;
case TDCLR:
/*
Erase the screen. Home the cursor to the top left hand
corner of the screen.
*/
strbuf_catf(outbuf, "\033[2J\033[H");
break;
case TDBEL:
/*
Generate an audio tone, bell, whatever.
*/
strbuf_catf(outbuf, "\007");
break;
case TDILP:
/*
Insert blank lines at the cursor; followed by a byte
containing a count of the number of blank lines to
insert. The cursor is unmoved. The line the cursor is
on and all lines below it move down; lines moved off the
bottom of the screen are lost.
*/
strbuf_catf(outbuf, "\033[%dL", supdup->td_args[0]);
break;
case TDDLP:
/*
Delete lines at the cursor; followed by a count. The
cursor is unmoved. The first line deleted is the one
the cursor is on. Lines below those deleted move up.
Newly- created lines at the bottom of the screen are
blank.
*/
strbuf_catf(outbuf, "\033[%dM", supdup->td_args[0]);
break;
case TDICP:
/*
Insert blank character positions at the cursor; followed
by a count. The cursor is unmoved. The character the
cursor is on and all characters to the right on the
current line move to the right; characters moved off the
end of the line are lost.
*/
strbuf_catf(outbuf, "\033[%d@", supdup->td_args[0]);
break;
case TDDCP:
/*
Delete characters at the cursor; followed by a count.
The cursor is unmoved. The first character deleted is
the one the cursor is on. Newly-created characters at
the end of the line are blank.
*/
strbuf_catf(outbuf, "\033[%dP", supdup->td_args[0]);
break;
case TDBOW:
case TDRST:
/*
Display black characters on white screen.
HIGHLY OPTIONAL.
*/
// Since this is HIGHLY OPTIONAL, I'm not going
// to implement it yet.
break;
/*
* Non-standard (whatever "standard" means here) SUPDUP
* commands. These are used (at the very least) by
* Genera's SUPDUP implementation. Cannot find any
* official documentation, behavior is based on UNIX
* SUPDUP implementation from MIT.
*/
case TDBS:
/*
* Backspace -- move cursor back one character (does not
* appear to wrap...)
*/
put_byte(outbuf, '\010');
break;
case TDLF:
/*
* Linefeed -- move cursor down one line (again, no wrapping)
*/
put_byte(outbuf, '\012');
break;
case TDCR:
/*
* Carriage return -- move cursor to start of current line.
*/
put_byte(outbuf, '\015');
break;
}
// Return to top level to pick up the next %TD code or
// printable character.
supdup->tdstate = TD_TOPLEVEL;
}
static void term_out_supdup(Supdup *supdup, strbuf *outbuf, int c)
{
if (supdup->tdstate == TD_TOPLEVEL) {
do_toplevel (supdup, outbuf, c);
} else if (supdup->tdstate == TD_ARGS) {
do_args (supdup, outbuf, c);
}
// If all arguments for a %TD code are ready, we will execute the code now.
if (supdup->tdstate == TD_ARGSDONE) {
do_argsdone (supdup, outbuf, c);
}
}
static void do_supdup_read(Supdup *supdup, const char *buf, size_t len)
{
strbuf *outbuf = strbuf_new();
while (len--) {
int c = (unsigned char)*buf++;
switch (supdup->state) {
case CONNECTING:
// "Following the transmission of the terminal options by
// the user, the server should respond with an ASCII
// greeting message, terminated with a %TDNOP code..."
if (TDNOP == c) {
// Greeting done, switch to the CONNECTED state.
supdup->state = CONNECTED;
supdup->tdstate = TD_TOPLEVEL;
} else {
// Forward the greeting message (which is straight
// ASCII, no controls) on so it gets displayed TODO:
// filter out only printable chars?
put_byte(outbuf, c);
}
break;
case CONNECTED:
// "All transmissions from the server after the %TDNOP
// [see above] are either printing characters or virtual
// terminal display codes." Forward these on to the
// frontend which will decide what to do with them.
term_out_supdup(supdup, outbuf, c);
/*
* Hack to make Symbolics Genera SUPDUP happy: Wait until
* after we're connected (finished the initial handshake
* and have gotten additional data) before sending the
* location string. For some reason doing so earlier
* causes the Symbolics SUPDUP to end up in an odd state.
*/
if (!supdup->sent_location) {
supdup_send_location(supdup);
supdup->sent_location = true;
}
break;
}
if (outbuf->len >= 4096) {
c_write(supdup, outbuf->u, outbuf->len);
outbuf->len = 0;
}
}
if (outbuf->len)
c_write(supdup, outbuf->u, outbuf->len);
strbuf_free(outbuf);
}
static void supdup_log(Plug *plug, PlugLogType type, SockAddr *addr, int port,
const char *error_msg, int error_code)
{
Supdup *supdup = container_of(plug, Supdup, plug);
backend_socket_log(supdup->seat, supdup->logctx, type, addr, port,
error_msg, error_code,
supdup->conf, supdup->state != CONNECTING);
}
static void supdup_closing(Plug *plug, const char *error_msg, int error_code,
bool calling_back)
{
Supdup *supdup = container_of(plug, Supdup, plug);
/*
* We don't implement independent EOF in each direction for Telnet
* connections; as soon as we get word that the remote side has
* sent us EOF, we wind up the whole connection.
*/
if (supdup->s) {
sk_close(supdup->s);
supdup->s = NULL;
if (error_msg)
supdup->closed_on_socket_error = true;
seat_notify_remote_exit(supdup->seat);
}
if (error_msg) {
logevent(supdup->logctx, error_msg);
seat_connection_fatal(supdup->seat, "%s", error_msg);
}
/* Otherwise, the remote side closed the connection normally. */
}
static void supdup_receive(Plug *plug, int urgent, const char *data, size_t len)
{
Supdup *supdup = container_of(plug, Supdup, plug);
do_supdup_read(supdup, data, len);
}
static void supdup_sent(Plug *plug, size_t bufsize)
{
Supdup *supdup = container_of(plug, Supdup, plug);
supdup->bufsize = bufsize;
}
static void supdup_send_36bits(Supdup *supdup, unsigned long long thirtysix)
{
//
// From RFC734:
// "Each word is sent through the 8-bit connection as six
// 6-bit bytes, most-significant first."
//
// Split the 36-bit word into 6 6-bit "bytes", packed into
// 8-bit bytes and send, most-significant byte first.
//
for (int i = 5; i >= 0; i--) {
char sixBits = (thirtysix >> (i * 6)) & 077;
sk_write(supdup->s, &sixBits, 1);
}
}
static void supdup_send_config(Supdup *supdup)
{
supdup_send_36bits(supdup, WORDS); // negative length
supdup_send_36bits(supdup, TCTYP); // terminal type
supdup_send_36bits(supdup, supdup->ttyopt); // options
supdup_send_36bits(supdup, supdup->tcmxv); // height
supdup_send_36bits(supdup, supdup->tcmxh); // width
supdup_send_36bits(supdup, TTYROL); // scroll amount
}
/*
* Called to set up the Supdup connection.
*
* Returns an error message, or NULL on success.
*
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static char *supdup_init(const BackendVtable *x, Seat *seat,
Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port, char **realhost,
bool nodelay, bool keepalive)
{
static const PlugVtable fn_table = {
.log = supdup_log,
.closing = supdup_closing,
.receive = supdup_receive,
.sent = supdup_sent,
};
SockAddr *addr;
const char *err;
Supdup *supdup;
char *loghost;
int addressfamily;
const char *utf8 = "\033%G";
supdup = snew(struct supdup_tag);
supdup->plug.vt = &fn_table;
supdup->backend.vt = &supdup_backend;
supdup->logctx = logctx;
supdup->conf = conf_copy(conf);
supdup->s = NULL;
supdup->closed_on_socket_error = false;
supdup->seat = seat;
supdup->term_width = conf_get_int(supdup->conf, CONF_width);
supdup->term_height = conf_get_int(supdup->conf, CONF_height);
supdup->pinger = NULL;
supdup->sent_location = false;
*backend_handle = &supdup->backend;
switch (conf_get_int(supdup->conf, CONF_supdup_ascii_set)) {
case SUPDUP_CHARSET_ASCII:
supdup->print = print_ascii;
break;
case SUPDUP_CHARSET_ITS:
supdup->print = print_its;
break;
case SUPDUP_CHARSET_WAITS:
supdup->print = print_waits;
break;
}
/*
* Try to find host.
*/
{
char *buf;
addressfamily = conf_get_int(supdup->conf, CONF_addressfamily);
buf = dupprintf("Looking up host \"%s\"%s", host,
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
"")));
logevent(supdup->logctx, buf);
sfree(buf);
}
addr = name_lookup(host, port, realhost, supdup->conf, addressfamily, NULL, "");
if ((err = sk_addr_error(addr)) != NULL) {
sk_addr_free(addr);
return dupstr(err);
}
if (port < 0)
port = 0137; /* default supdup port */
/*
* Open socket.
*/
supdup->s = new_connection(addr, *realhost, port, false, true,
nodelay, keepalive, &supdup->plug, supdup->conf);
if ((err = sk_socket_error(supdup->s)) != NULL)
return dupstr(err);
supdup->pinger = pinger_new(supdup->conf, &supdup->backend);
/*
* We can send special commands from the start.
*/
seat_update_specials_menu(supdup->seat);
/*
* loghost overrides realhost, if specified.
*/
loghost = conf_get_str(supdup->conf, CONF_loghost);
if (*loghost) {
char *colon;
sfree(*realhost);
*realhost = dupstr(loghost);
colon = host_strrchr(*realhost, ':');
if (colon)
*colon++ = '\0';
}
/*
* Set up TTYOPTS based on config
*/
int ascii_set = conf_get_int(supdup->conf, CONF_supdup_ascii_set);
int more_processing = conf_get_bool(supdup->conf, CONF_supdup_more);
int scrolling = conf_get_bool(supdup->conf, CONF_supdup_scroll);
supdup->ttyopt =
TOERS |
TOMVB |
(ascii_set == SUPDUP_CHARSET_ASCII ? 0 : TOSAI | TOSA1) |
TOMVU |
TOLWR |
TOLID |
TOCID |
TPCBS |
(scrolling ? TOROL : 0) |
(more_processing ? TOMOR : 0) |
TPORS;
supdup->tcmxh = supdup->term_width - 1; // -1 "..one column is used to indicate line continuation."
supdup->tcmxv = supdup->term_height;
/*
* Send our configuration words to the server
*/
supdup_send_config(supdup);
/*
* We next expect a connection message followed by %TDNOP from the server
*/
supdup->state = CONNECTING;
seat_set_trust_status(supdup->seat, false);
/* Make sure the terminal is in UTF-8 mode. */
c_write(supdup, (unsigned char *)utf8, strlen(utf8));
return NULL;
}
static void supdup_free(Backend *be)
{
Supdup *supdup = container_of(be, Supdup, backend);
if (supdup->s)
sk_close(supdup->s);
if (supdup->pinger)
pinger_free(supdup->pinger);
conf_free(supdup->conf);
sfree(supdup);
}
/*
* Reconfigure the Supdup backend.
*/
static void supdup_reconfig(Backend *be, Conf *conf)
{
/* Nothing to do; SUPDUP cannot be reconfigured while running. */
}
/*
* Called to send data down the Supdup connection.
*/
static size_t supdup_send(Backend *be, const char *buf, size_t len)
{
Supdup *supdup = container_of(be, Supdup, backend);
char c;
int i;
if (supdup->s == NULL)
return 0;
for (i = 0; i < len; i++) {
if (buf[i] == 034)
supdup->bufsize = sk_write(supdup->s, "\034\034", 2);
else {
c = buf[i] & 0177;
supdup->bufsize = sk_write(supdup->s, &c, 1);
}
}
return supdup->bufsize;
}
/*
* Called to query the current socket sendability status.
*/
static size_t supdup_sendbuffer(Backend *be)
{
Supdup *supdup = container_of(be, Supdup, backend);
return supdup->bufsize;
}
/*
* Called to set the size of the window from Supdup's POV.
*/
static void supdup_size(Backend *be, int width, int height)
{
Supdup *supdup = container_of(be, Supdup, backend);
supdup->term_width = width;
supdup->term_height = height;
//
// SUPDUP does not support resizing the terminal after connection
// establishment.
//
}
/*
* Send Telnet special codes.
*/
static void supdup_special(Backend *be, SessionSpecialCode code, int arg)
{
}
static const SessionSpecial *supdup_get_specials(Backend *be)
{
return NULL;
}
static bool supdup_connected(Backend *be)
{
Supdup *supdup = container_of(be, Supdup, backend);
return supdup->s != NULL;
}
static bool supdup_sendok(Backend *be)
{
return 1;
}
static void supdup_unthrottle(Backend *be, size_t backlog)
{
Supdup *supdup = container_of(be, Supdup, backend);
sk_set_frozen(supdup->s, backlog > SUPDUP_MAX_BACKLOG);
}
static bool supdup_ldisc(Backend *be, int option)
{
/* No support for echoing or local editing. */
return false;
}
static void supdup_provide_ldisc(Backend *be, Ldisc *ldisc)
{
}
static int supdup_exitcode(Backend *be)
{
Supdup *supdup = container_of(be, Supdup, backend);
if (supdup->s != NULL)
return -1; /* still connected */
else if (supdup->closed_on_socket_error)
return INT_MAX; /* a socket error counts as an unclean exit */
else
/* Supdup doesn't transmit exit codes back to the client */
return 0;
}
/*
* cfg_info for Dupdup does nothing at all.
*/
static int supdup_cfg_info(Backend *be)
{
return 0;
}
const BackendVtable supdup_backend = {
.init = supdup_init,
.free = supdup_free,
.reconfig = supdup_reconfig,
.send = supdup_send,
.sendbuffer = supdup_sendbuffer,
.size = supdup_size,
.special = supdup_special,
.get_specials = supdup_get_specials,
.connected = supdup_connected,
.exitcode = supdup_exitcode,
.sendok = supdup_sendok,
.ldisc_option_state = supdup_ldisc,
.provide_ldisc = supdup_provide_ldisc,
.unthrottle = supdup_unthrottle,
.cfg_info = supdup_cfg_info,
.id = "supdup",
.displayname = "SUPDUP",
.protocol = PROT_SUPDUP,
.default_port = 0137,
.flags = BACKEND_RESIZE_FORBIDDEN | BACKEND_NEEDS_TERMINAL,
};

1070
otherbackends/telnet.c Normal file

File diff suppressed because it is too large Load Diff

214
otherbackends/testback.c Normal file
View File

@ -0,0 +1,214 @@
/*
* Copyright (c) 1999 Simon Tatham
* Copyright (c) 1999 Ben Harris
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* PuTTY test backends */
#include <stdio.h>
#include <stdlib.h>
#include "putty.h"
static char *null_init(const BackendVtable *, Seat *, Backend **, LogContext *,
Conf *, const char *, int, char **, bool, bool);
static char *loop_init(const BackendVtable *, Seat *, Backend **, LogContext *,
Conf *, const char *, int, char **, bool, bool);
static void null_free(Backend *);
static void loop_free(Backend *);
static void null_reconfig(Backend *, Conf *);
static size_t null_send(Backend *, const char *, size_t);
static size_t loop_send(Backend *, const char *, size_t);
static size_t null_sendbuffer(Backend *);
static void null_size(Backend *, int, int);
static void null_special(Backend *, SessionSpecialCode, int);
static const SessionSpecial *null_get_specials(Backend *);
static bool null_connected(Backend *);
static int null_exitcode(Backend *);
static bool null_sendok(Backend *);
static bool null_ldisc(Backend *, int);
static void null_provide_ldisc(Backend *, Ldisc *);
static void null_unthrottle(Backend *, size_t);
static int null_cfg_info(Backend *);
const BackendVtable null_backend = {
.init = null_init,
.free = null_free,
.reconfig = null_reconfig,
.send = null_send,
.sendbuffer = null_sendbuffer,
.size = null_size,
.special = null_special,
.get_specials = null_get_specials,
.connected = null_connected,
.exitcode = null_exitcode,
.sendok = null_sendok,
.ldisc_option_state = null_ldisc,
.provide_ldisc = null_provide_ldisc,
.unthrottle = null_unthrottle,
.cfg_info = null_cfg_info,
.id = "null",
.displayname = "null",
.protocol = -1,
.default_port = 0,
};
const BackendVtable loop_backend = {
.init = loop_init,
.free = loop_free,
.reconfig = null_reconfig,
.send = loop_send,
.sendbuffer = null_sendbuffer,
.size = null_size,
.special = null_special,
.get_specials = null_get_specials,
.connected = null_connected,
.exitcode = null_exitcode,
.sendok = null_sendok,
.ldisc_option_state = null_ldisc,
.provide_ldisc = null_provide_ldisc,
.unthrottle = null_unthrottle,
.cfg_info = null_cfg_info,
.id = "loop",
.displayname = "loop",
.protocol = -1,
.default_port = 0,
};
struct loop_state {
Seat *seat;
Backend backend;
};
static char *null_init(const BackendVtable *vt, Seat *seat,
Backend **backend_handle, LogContext *logctx,
Conf *conf, const char *host, int port,
char **realhost, bool nodelay, bool keepalive) {
/* No local authentication phase in this protocol */
seat_set_trust_status(seat, false);
*backend_handle = NULL;
return NULL;
}
static char *loop_init(const BackendVtable *vt, Seat *seat,
Backend **backend_handle, LogContext *logctx,
Conf *conf, const char *host, int port,
char **realhost, bool nodelay, bool keepalive) {
struct loop_state *st = snew(struct loop_state);
/* No local authentication phase in this protocol */
seat_set_trust_status(seat, false);
st->seat = seat;
*backend_handle = &st->backend;
return NULL;
}
static void null_free(Backend *be)
{
}
static void loop_free(Backend *be)
{
struct loop_state *st = container_of(be, struct loop_state, backend);
sfree(st);
}
static void null_reconfig(Backend *be, Conf *conf) {
}
static size_t null_send(Backend *be, const char *buf, size_t len) {
return 0;
}
static size_t loop_send(Backend *be, const char *buf, size_t len) {
struct loop_state *st = container_of(be, struct loop_state, backend);
return seat_output(st->seat, 0, buf, len);
}
static size_t null_sendbuffer(Backend *be) {
return 0;
}
static void null_size(Backend *be, int width, int height) {
}
static void null_special(Backend *be, SessionSpecialCode code, int arg) {
}
static const SessionSpecial *null_get_specials (Backend *be) {
return NULL;
}
static bool null_connected(Backend *be) {
return false;
}
static int null_exitcode(Backend *be) {
return 0;
}
static bool null_sendok(Backend *be) {
return true;
}
static void null_unthrottle(Backend *be, size_t backlog) {
}
static bool null_ldisc(Backend *be, int option) {
return false;
}
static void null_provide_ldisc (Backend *be, Ldisc *ldisc) {
}
static int null_cfg_info(Backend *be)
{
return 0;
}
/*
* Emacs magic:
* Local Variables:
* c-file-style: "simon"
* End:
*/