xref: /freebsd/crypto/heimdal/appl/telnet/telnetd/termstat.c (revision 6a068746777241722b2b32c5d0bc443a2a64d80b)
113e3f4d6SMark Murray /*
213e3f4d6SMark Murray  * Copyright (c) 1989, 1993
313e3f4d6SMark Murray  *	The Regents of the University of California.  All rights reserved.
413e3f4d6SMark Murray  *
513e3f4d6SMark Murray  * Redistribution and use in source and binary forms, with or without
613e3f4d6SMark Murray  * modification, are permitted provided that the following conditions
713e3f4d6SMark Murray  * are met:
813e3f4d6SMark Murray  * 1. Redistributions of source code must retain the above copyright
913e3f4d6SMark Murray  *    notice, this list of conditions and the following disclaimer.
1013e3f4d6SMark Murray  * 2. Redistributions in binary form must reproduce the above copyright
1113e3f4d6SMark Murray  *    notice, this list of conditions and the following disclaimer in the
1213e3f4d6SMark Murray  *    documentation and/or other materials provided with the distribution.
1313e3f4d6SMark Murray  * 3. All advertising materials mentioning features or use of this software
1413e3f4d6SMark Murray  *    must display the following acknowledgement:
1513e3f4d6SMark Murray  *	This product includes software developed by the University of
1613e3f4d6SMark Murray  *	California, Berkeley and its contributors.
1713e3f4d6SMark Murray  * 4. Neither the name of the University nor the names of its contributors
1813e3f4d6SMark Murray  *    may be used to endorse or promote products derived from this software
1913e3f4d6SMark Murray  *    without specific prior written permission.
2013e3f4d6SMark Murray  *
2113e3f4d6SMark Murray  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2213e3f4d6SMark Murray  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2313e3f4d6SMark Murray  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2413e3f4d6SMark Murray  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2513e3f4d6SMark Murray  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2613e3f4d6SMark Murray  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2713e3f4d6SMark Murray  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2813e3f4d6SMark Murray  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2913e3f4d6SMark Murray  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3013e3f4d6SMark Murray  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3113e3f4d6SMark Murray  * SUCH DAMAGE.
3213e3f4d6SMark Murray  */
3313e3f4d6SMark Murray 
3413e3f4d6SMark Murray #include "telnetd.h"
3513e3f4d6SMark Murray 
36*ae771770SStanislav Sedov RCSID("$Id$");
3713e3f4d6SMark Murray 
3813e3f4d6SMark Murray /*
3913e3f4d6SMark Murray  * local variables
4013e3f4d6SMark Murray  */
4113e3f4d6SMark Murray int def_tspeed = -1, def_rspeed = -1;
4213e3f4d6SMark Murray #ifdef	TIOCSWINSZ
4313e3f4d6SMark Murray int def_row = 0, def_col = 0;
4413e3f4d6SMark Murray #endif
4513e3f4d6SMark Murray 
4613e3f4d6SMark Murray /*
4713e3f4d6SMark Murray  * flowstat
4813e3f4d6SMark Murray  *
4913e3f4d6SMark Murray  * Check for changes to flow control
5013e3f4d6SMark Murray  */
5113e3f4d6SMark Murray void
flowstat(void)524137ff4cSJacques Vidrine flowstat(void)
5313e3f4d6SMark Murray {
5413e3f4d6SMark Murray     if (his_state_is_will(TELOPT_LFLOW)) {
5513e3f4d6SMark Murray 	if (tty_flowmode() != flowmode) {
5613e3f4d6SMark Murray 	    flowmode = tty_flowmode();
5713e3f4d6SMark Murray 	    output_data("%c%c%c%c%c%c",
5813e3f4d6SMark Murray 			IAC, SB, TELOPT_LFLOW,
5913e3f4d6SMark Murray 			flowmode ? LFLOW_ON : LFLOW_OFF,
6013e3f4d6SMark Murray 			IAC, SE);
6113e3f4d6SMark Murray 	}
6213e3f4d6SMark Murray 	if (tty_restartany() != restartany) {
6313e3f4d6SMark Murray 	    restartany = tty_restartany();
6413e3f4d6SMark Murray 	    output_data("%c%c%c%c%c%c",
6513e3f4d6SMark Murray 			IAC, SB, TELOPT_LFLOW,
6613e3f4d6SMark Murray 			restartany ? LFLOW_RESTART_ANY
6713e3f4d6SMark Murray 			: LFLOW_RESTART_XON,
6813e3f4d6SMark Murray 			IAC, SE);
6913e3f4d6SMark Murray 	}
7013e3f4d6SMark Murray     }
7113e3f4d6SMark Murray }
7213e3f4d6SMark Murray 
7313e3f4d6SMark Murray /*
7413e3f4d6SMark Murray  * clientstat
7513e3f4d6SMark Murray  *
7613e3f4d6SMark Murray  * Process linemode related requests from the client.
7713e3f4d6SMark Murray  * Client can request a change to only one of linemode, editmode or slc's
7813e3f4d6SMark Murray  * at a time, and if using kludge linemode, then only linemode may be
7913e3f4d6SMark Murray  * affected.
8013e3f4d6SMark Murray  */
8113e3f4d6SMark Murray void
clientstat(int code,int parm1,int parm2)8213e3f4d6SMark Murray clientstat(int code, int parm1, int parm2)
8313e3f4d6SMark Murray {
8413e3f4d6SMark Murray     /*
8513e3f4d6SMark Murray      * Get a copy of terminal characteristics.
8613e3f4d6SMark Murray      */
8713e3f4d6SMark Murray     init_termbuf();
8813e3f4d6SMark Murray 
8913e3f4d6SMark Murray     /*
9013e3f4d6SMark Murray      * Process request from client. code tells what it is.
9113e3f4d6SMark Murray      */
9213e3f4d6SMark Murray     switch (code) {
9313e3f4d6SMark Murray     case TELOPT_NAWS:
9413e3f4d6SMark Murray #ifdef	TIOCSWINSZ
9513e3f4d6SMark Murray 	{
9613e3f4d6SMark Murray 	    struct winsize ws;
9713e3f4d6SMark Murray 
9813e3f4d6SMark Murray 	    def_col = parm1;
9913e3f4d6SMark Murray 	    def_row = parm2;
10013e3f4d6SMark Murray 
10113e3f4d6SMark Murray 	    /*
10213e3f4d6SMark Murray 	     * Change window size as requested by client.
10313e3f4d6SMark Murray 	     */
10413e3f4d6SMark Murray 
10513e3f4d6SMark Murray 	    ws.ws_col = parm1;
10613e3f4d6SMark Murray 	    ws.ws_row = parm2;
10713e3f4d6SMark Murray 	    ioctl(ourpty, TIOCSWINSZ, (char *)&ws);
10813e3f4d6SMark Murray 	}
10913e3f4d6SMark Murray #endif	/* TIOCSWINSZ */
11013e3f4d6SMark Murray 
11113e3f4d6SMark Murray     break;
11213e3f4d6SMark Murray 
11313e3f4d6SMark Murray     case TELOPT_TSPEED:
11413e3f4d6SMark Murray 	{
11513e3f4d6SMark Murray 	    def_tspeed = parm1;
11613e3f4d6SMark Murray 	    def_rspeed = parm2;
11713e3f4d6SMark Murray 	    /*
11813e3f4d6SMark Murray 	     * Change terminal speed as requested by client.
11913e3f4d6SMark Murray 	     * We set the receive speed first, so that if we can't
12013e3f4d6SMark Murray 	     * store seperate receive and transmit speeds, the transmit
12113e3f4d6SMark Murray 	     * speed will take precedence.
12213e3f4d6SMark Murray 	     */
12313e3f4d6SMark Murray 	    tty_rspeed(parm2);
12413e3f4d6SMark Murray 	    tty_tspeed(parm1);
12513e3f4d6SMark Murray 	    set_termbuf();
12613e3f4d6SMark Murray 
12713e3f4d6SMark Murray 	    break;
12813e3f4d6SMark Murray 
12913e3f4d6SMark Murray 	}  /* end of case TELOPT_TSPEED */
13013e3f4d6SMark Murray 
13113e3f4d6SMark Murray     default:
13213e3f4d6SMark Murray 	/* What? */
13313e3f4d6SMark Murray 	break;
13413e3f4d6SMark Murray     }  /* end of switch */
13513e3f4d6SMark Murray 
13613e3f4d6SMark Murray     netflush();
13713e3f4d6SMark Murray 
13813e3f4d6SMark Murray }
139