mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
b4c8fd9d86
This is a new vtable-based abstraction which is passed to a backend in place of Frontend, and it implements only the subset of the Frontend functions needed by a backend. (Many other Frontend functions still exist, notably the wide range of things called by terminal.c providing platform-independent operations on the GUI terminal window.) The purpose of making it a vtable is that this opens up the possibility of creating a backend as an internal implementation detail of some other activity, by providing just that one backend with a custom Seat that implements the methods differently. For example, this refactoring should make it feasible to directly implement an SSH proxy type, aka the 'jump host' feature supported by OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP mode, and then expose the main channel of that as the Socket for the primary connection'. (Which of course you can already do by spawning 'plink -nc' as a separate proxy process, but this would permit it in the _same_ process without anything getting confused.) I've centralised a full set of stub methods in misc.c for the new abstraction, which allows me to get rid of several annoying stubs in the previous code. Also, while I'm here, I've moved a lot of duplicated modalfatalbox() type functions from application main program files into wincons.c / uxcons.c, which I think saves duplication overall. (A minor visible effect is that the prefixes on those console-based fatal error messages will now be more consistent between applications.)
179 lines
4.8 KiB
C
179 lines
4.8 KiB
C
/*
|
|
* 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 const char *null_init(Seat *, Backend **, LogContext *, Conf *,
|
|
const char *, int, char **, int, int);
|
|
static const char *loop_init(Seat *, Backend **, LogContext *, Conf *,
|
|
const char *, int, char **, int, int);
|
|
static void null_free(Backend *);
|
|
static void loop_free(Backend *);
|
|
static void null_reconfig(Backend *, Conf *);
|
|
static int null_send(Backend *, const char *, int);
|
|
static int loop_send(Backend *, const char *, int);
|
|
static int 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 int null_connected(Backend *);
|
|
static int null_exitcode(Backend *);
|
|
static int null_sendok(Backend *);
|
|
static int null_ldisc(Backend *, int);
|
|
static void null_provide_ldisc(Backend *, Ldisc *);
|
|
static void null_unthrottle(Backend *, int);
|
|
static int null_cfg_info(Backend *);
|
|
|
|
const struct BackendVtable null_backend = {
|
|
null_init, null_free, null_reconfig, null_send, null_sendbuffer, null_size,
|
|
null_special, null_get_specials, null_connected, null_exitcode, null_sendok,
|
|
null_ldisc, null_provide_ldisc, null_unthrottle,
|
|
null_cfg_info, NULL /* test_for_upstream */, "null", -1, 0
|
|
};
|
|
|
|
const struct BackendVtable loop_backend = {
|
|
loop_init, loop_free, null_reconfig, loop_send, null_sendbuffer, null_size,
|
|
null_special, null_get_specials, null_connected, null_exitcode, null_sendok,
|
|
null_ldisc, null_provide_ldisc, null_unthrottle,
|
|
null_cfg_info, NULL /* test_for_upstream */, "loop", -1, 0
|
|
};
|
|
|
|
struct loop_state {
|
|
Seat *seat;
|
|
Backend backend;
|
|
};
|
|
|
|
static const char *null_init(Seat *seat, Backend **backend_handle,
|
|
LogContext *logctx, Conf *conf,
|
|
const char *host, int port, char **realhost,
|
|
int nodelay, int keepalive) {
|
|
*backend_handle = NULL;
|
|
return NULL;
|
|
}
|
|
|
|
static const char *loop_init(Seat *seat, Backend **backend_handle,
|
|
LogContext *logctx, Conf *conf,
|
|
const char *host, int port, char **realhost,
|
|
int nodelay, int keepalive) {
|
|
struct loop_state *st = snew(struct loop_state);
|
|
|
|
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 int null_send(Backend *be, const char *buf, int len) {
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int loop_send(Backend *be, const char *buf, int len) {
|
|
struct loop_state *st = container_of(be, struct loop_state, backend);
|
|
|
|
return seat_output(st->seat, 0, buf, len);
|
|
}
|
|
|
|
static int 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 int null_connected(Backend *be) {
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int null_exitcode(Backend *be) {
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int null_sendok(Backend *be) {
|
|
|
|
return 1;
|
|
}
|
|
|
|
static void null_unthrottle(Backend *be, int backlog) {
|
|
|
|
}
|
|
|
|
static int null_ldisc(Backend *be, int option) {
|
|
|
|
return 0;
|
|
}
|
|
|
|
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:
|
|
*/
|