1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Port forwarding module now passes backend handles around properly.

As a result I've now been able to turn the global variables `back'
and `backhandle' into module-level statics in the individual front
ends. Now _that's_ progress!

[originally from svn r2142]
This commit is contained in:
Simon Tatham 2002-10-26 10:33:59 +00:00
parent 0b2523eeda
commit 24530b945e
10 changed files with 42 additions and 38 deletions

View File

@ -69,6 +69,9 @@ DWORD orig_console_mode;
WSAEVENT netevent;
static Backend *back;
static void *backhandle;
int term_ldisc(Terminal *term, int mode)
{
return FALSE;

View File

@ -61,6 +61,8 @@ struct PFwdPrivate {
struct plug_function_table *fn;
/* the above variable absolutely *must* be the first in this structure */
void *c; /* (channel) data used by ssh.c */
void *backhandle; /* instance of SSH backend itself */
/* Note that backhandle need not be filled in if c is non-NULL */
Socket s;
char hostname[128];
int throttled, throttle_override;
@ -137,6 +139,7 @@ char *pfd_newconnect(Socket *s, char *hostname, int port, void *c)
pr->throttled = pr->throttle_override = 0;
pr->ready = 1;
pr->c = c;
pr->backhandle = NULL; /* we shouldn't need this */
pr->s = *s = new_connection(addr, dummy_realhost, port, 0, 1, 0, (Plug) pr);
if ((err = sk_socket_error(*s))) {
@ -170,6 +173,7 @@ static int pfd_accepting(Plug p, void *sock)
pr->fn = &fn_table;
pr->c = NULL;
pr->backhandle = org->backhandle;
pr->s = s = sk_register(sock, (Plug) pr);
if ((err = sk_socket_error(s))) {
@ -177,7 +181,7 @@ static int pfd_accepting(Plug p, void *sock)
return err != NULL;
}
pr->c = new_sock_channel(backhandle, s);
pr->c = new_sock_channel(org->backhandle, s);
strcpy(pr->hostname, org->hostname);
pr->port = org->port;
@ -192,8 +196,7 @@ static int pfd_accepting(Plug p, void *sock)
return 1;
} else {
/* asks to forward to the specified host/port for this */
ssh_send_port_open(backhandle, pr->c, pr->hostname,
pr->port, "forwarding");
ssh_send_port_open(pr->c, pr->hostname, pr->port, "forwarding");
}
return 0;
@ -203,7 +206,7 @@ static int pfd_accepting(Plug p, void *sock)
/* Add a new forwarding from port -> desthost:destport
sets up a listener on the local machine on port
*/
char *pfd_addforward(char *desthost, int destport, int port)
char *pfd_addforward(char *desthost, int destport, int port, void *backhandle)
{
static struct plug_function_table fn_table = {
pfd_closing,
@ -227,6 +230,7 @@ char *pfd_addforward(char *desthost, int destport, int port)
pr->throttled = pr->throttle_override = 0;
pr->ready = 0;
pr->waiting = NULL;
pr->backhandle = backhandle;
pr->s = s = new_listener(port, (Plug) pr, !cfg.lport_acceptall);
if ((err = sk_socket_error(s))) {

View File

@ -32,6 +32,8 @@ static int do_sftp_init(void);
*/
char *pwd, *homedir;
static Backend *back;
static void *backhandle;
/* ----------------------------------------------------------------------
* Higher-level helper functions used in commands.
@ -1484,7 +1486,7 @@ void connection_fatal(char *fmt, ...)
cleanup_exit(1);
}
void ldisc_send(char *buf, int len, int interactive)
void ldisc_send(void *handle, char *buf, int len, int interactive)
{
/*
* This is only here because of the calls to ldisc_send(NULL,

17
putty.h
View File

@ -23,17 +23,6 @@ typedef struct terminal_tag Terminal;
#include "puttyps.h"
#include "network.h"
/*
* Global variables. Most modules declare these `extern', but
* window.c will do `#define PUTTY_DO_GLOBALS' before including this
* module, and so will get them properly defined.
*/
#ifdef PUTTY_DO_GLOBALS
#define GLOBAL
#else
#define GLOBAL extern
#endif
/* Three attribute types:
* The ATTRs (normal attributes) are stored with the characters in the main
* display arrays
@ -104,9 +93,6 @@ GLOBAL int alt_pressed;
GLOBAL int session_closed;
GLOBAL char *help_path;
GLOBAL int help_has_contents;
GLOBAL int nsessions;
GLOBAL char **sessions;
@ -209,9 +195,6 @@ struct backend_tag {
int default_port;
};
GLOBAL Backend *back;
GLOBAL void *backhandle;
extern struct backend_list {
int protocol;
char *name;

5
scp.c
View File

@ -99,6 +99,9 @@ static int gui_mode = 0;
static char *gui_hwnd = NULL;
static int using_sftp = 0;
static Backend *back;
static void *backhandle;
static void source(char *src);
static void rsource(char *src);
static void sink(char *targ, char *src);
@ -117,7 +120,7 @@ static void gui_update_stats(char *name, unsigned long size,
*/
#define MAX_SCP_BUFSIZE 16384
void ldisc_send(char *buf, int len, int interactive)
void ldisc_send(void *handle, char *buf, int len, int interactive)
{
/*
* This is only here because of the calls to ldisc_send(NULL,

12
ssh.c
View File

@ -320,7 +320,8 @@ extern void x11_unthrottle(Socket s);
extern void x11_override_throttle(Socket s, int enable);
extern char *pfd_newconnect(Socket * s, char *hostname, int port, void *c);
extern char *pfd_addforward(char *desthost, int destport, int port);
extern char *pfd_addforward(char *desthost, int destport, int port,
void *backhandle);
extern void pfd_close(Socket s);
extern int pfd_send(Socket s, char *data, int len);
extern void pfd_confirm(Socket s);
@ -3113,7 +3114,7 @@ static void ssh1_protocol(Ssh ssh, unsigned char *in, int inlen, int ispkt)
}
if (sport && dport) {
if (type == 'L') {
pfd_addforward(host, dport, sport);
pfd_addforward(host, dport, sport, ssh);
sprintf(buf, "Local port %.*s%.*s%d%.*s forwarding to"
" %s:%.*s%.*s%d%.*s",
sserv ? strlen(sports) : 0, sports,
@ -5155,7 +5156,7 @@ static void do_ssh2_authconn(Ssh ssh, unsigned char *in, int inlen, int ispkt)
}
if (sport && dport) {
if (type == 'L') {
pfd_addforward(host, dport, sport);
pfd_addforward(host, dport, sport, ssh);
sprintf(buf, "Local port %.*s%.*s%d%.*s forwarding to"
" %s:%.*s%.*s%d%.*s",
sserv ? strlen(sports) : 0, sports,
@ -6077,11 +6078,10 @@ void ssh_unthrottle(void *handle, int bufsize)
}
}
void ssh_send_port_open(void *handle, void *channel, char *hostname,
int port, char *org)
void ssh_send_port_open(void *channel, char *hostname, int port, char *org)
{
Ssh ssh = (Ssh) handle;
struct ssh_channel *c = (struct ssh_channel *)channel;
Ssh ssh = c->ssh;
char buf[1024];
sprintf(buf, "Opening forwarded connection to %.512s:%d", hostname, port);

3
ssh.h
View File

@ -252,8 +252,7 @@ void logevent(char *);
/* Allocate and register a new channel for port forwarding */
void *new_sock_channel(void *handle, Socket s);
void ssh_send_port_open(void *handle, void *channel,
char *hostname, int port, char *org);
void ssh_send_port_open(void *channel, char *hostname, int port, char *org);
Bignum copybn(Bignum b);
Bignum bn_power_2(int n);

View File

@ -54,6 +54,8 @@ struct gui_data {
char icontitle[sizeof(((Config *)0)->wintitle)];
int master_fd, master_func_id, exited;
void *ldisc;
Backend *back;
void *backhandle;
};
static struct gui_data the_inst;
@ -887,8 +889,8 @@ void done_with_pty(struct gui_data *inst)
gtk_input_remove(inst->master_func_id);
}
if (!inst->exited && back->exitcode(backhandle) >= 0) {
int exitcode = back->exitcode(backhandle);
if (!inst->exited && inst->back->exitcode(inst->backhandle) >= 0) {
int exitcode = inst->back->exitcode(inst->backhandle);
int clean;
clean = WIFEXITED(exitcode) && (WEXITSTATUS(exitcode) == 0);
@ -941,7 +943,7 @@ gint timer_func(gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
if (back->exitcode(backhandle) >= 0) {
if (inst->back->exitcode(inst->backhandle) >= 0) {
/*
* The primary child process died. We could keep the
* terminal open for remaining subprocesses to output to,
@ -1962,14 +1964,14 @@ int main(int argc, char **argv)
term = term_init();
back = &pty_backend;
back->init((void *)term, &backhandle, NULL, 0, NULL, 0);
inst->back = &pty_backend;
inst->back->init((void *)term, &inst->backhandle, NULL, 0, NULL, 0);
term_provide_resize_fn(term, back->size, backhandle);
term_provide_resize_fn(term, inst->back->size, inst->backhandle);
term_size(term, cfg.height, cfg.width, cfg.savelines);
inst->ldisc = ldisc_create(term, back, backhandle, inst);
inst->ldisc = ldisc_create(term, inst->back, inst->backhandle, inst);
ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */
inst->master_fd = pty_master_fd;

View File

@ -116,6 +116,8 @@ static time_t last_movement = 0;
static int caret_x = -1, caret_y = -1;
static void *ldisc;
static Backend *back;
static void *backhandle;
#define FONT_NORMAL 0
#define FONT_BOLD 1

View File

@ -43,6 +43,12 @@ GLOBAL HWND logbox;
*/
GLOBAL HINSTANCE hinst;
/*
* Details of the help file.
*/
GLOBAL char *help_path;
GLOBAL int help_has_contents;
/*
* I've just looked in the windows standard headr files for WM_USER, there
* are hundreds of flags defined using the form WM_USER+123 so I've