X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/708bbbbe30a499a0a51e0356e7056206b15989fd..7e78000d8966255e919e3d8753fd784f4559ee55:/telnet.c diff --git a/telnet.c b/telnet.c index 8eb6e8a7..29daf0f1 100644 --- a/telnet.c +++ b/telnet.c @@ -132,6 +132,8 @@ static struct Opt *opts[] = { &o_we_sga, &o_they_sga, NULL }; +static int echoing = TRUE, editing = TRUE; + static int in_synch; static int sb_opt, sb_len; static char *sb_buf = NULL; @@ -170,8 +172,11 @@ static void deactivate_option (struct Opt *o) { * Generate side effects of enabling or disabling an option. */ static void option_side_effects(struct Opt *o, int enabled) { - if (o->option == TELOPT_ECHO && cfg.ldisc_term) - ldisc = enabled ? &ldisc_simple : &ldisc_term; + if (o->option == TELOPT_ECHO && o->send == DO) + echoing = !enabled; + else if (o->option == TELOPT_SGA && o->send == DO) + editing = !enabled; + ldisc_send(NULL, 0); /* cause ldisc to notice the change */ } static void activate_option (struct Opt *o) { @@ -460,13 +465,18 @@ static void do_telnet_read (char *buf, int len) { } } -static int telnet_receive(Socket s, int urgent, char *data, int len) { - if (!len) { - /* Connection has closed. */ - sk_close(s); - s = NULL; - return 0; - } +static int telnet_closing (Plug plug, char *error_msg, int error_code, int calling_back) { + sk_close(s); + s = NULL; + if (error_msg) { + /* A socket error has occurred. */ + connection_fatal (error_msg); + } /* Otherwise, the remote side closed the connection normally. */ + return 0; +} + +static int telnet_receive(Plug plug, int urgent, char *data, int len) { + if(urgent) in_synch = TRUE; do_telnet_read (data, len); return 1; } @@ -479,6 +489,11 @@ static int telnet_receive(Socket s, int urgent, char *data, int len) { * Also places the canonical host name into `realhost'. */ static char *telnet_init (char *host, int port, char **realhost) { + static struct plug_function_table fn_table = { + telnet_closing, + telnet_receive + }, *fn_table_ptr = &fn_table; + SockAddr addr; char *err; @@ -495,7 +510,7 @@ static char *telnet_init (char *host, int port, char **realhost) { /* * Open socket. */ - s = sk_new(addr, port, telnet_receive); + s = sk_new(addr, port, 0, 1, &fn_table_ptr); if ( (err = sk_socket_error(s)) ) return err; @@ -504,15 +519,6 @@ static char *telnet_init (char *host, int port, char **realhost) { /* * Initialise option states. */ - if( cfg.ldisc_term ) - { - struct Opt **o; - - for (o = opts; *o; o++) - if ((*o)->state == REQUESTED) - (*o)->state = INACTIVE; - } - else { struct Opt **o; @@ -526,11 +532,6 @@ static char *telnet_init (char *host, int port, char **realhost) { */ in_synch = FALSE; - /* - * We have no pre-session phase. - */ - begin_session(); - return NULL; } @@ -633,6 +634,12 @@ static Socket telnet_socket(void) { return s; } static int telnet_sendok(void) { return 1; } +static int telnet_ldisc(int option) { + if (option == LD_ECHO) return echoing; + if (option == LD_EDIT) return editing; + return FALSE; +} + Backend telnet_backend = { telnet_init, telnet_send, @@ -640,5 +647,6 @@ Backend telnet_backend = { telnet_special, telnet_socket, telnet_sendok, + telnet_ldisc, 23 };