欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

state.c

早期freebsd实现
C
第 1 页 / 共 3 页
字号:
		case TELOPT_LFLOW:			/*			 * If we are going to support flow control			 * option, then don't worry peer that we can't			 * change the flow control characters.			 */			slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;			slctab[SLC_XON].defset.flag |= SLC_DEFAULT;			slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;			slctab[SLC_XOFF].defset.flag |= SLC_DEFAULT;		case TELOPT_TTYPE:		case TELOPT_SGA:		case TELOPT_NAWS:		case TELOPT_TSPEED:		case TELOPT_XDISPLOC:		case TELOPT_NEW_ENVIRON:		case TELOPT_OLD_ENVIRON:			changeok++;			break;#ifdef	LINEMODE		case TELOPT_LINEMODE:# ifdef	KLUDGELINEMODE			/*			 * Note client's desire to use linemode.			 */			lmodetype = REAL_LINEMODE;# endif	/* KLUDGELINEMODE */			func = doclientstat;			changeok++;			break;#endif	/* LINEMODE */#ifdef	AUTHENTICATION		case TELOPT_AUTHENTICATION:			func = auth_request;			changeok++;			break;#endif#ifdef	ENCRYPTION		case TELOPT_ENCRYPT:			func = encrypt_send_support;			changeok++;			break;#endif	/* ENCRYPTION */		default:			break;		}		if (changeok) {			set_his_want_state_will(option);			send_do(option, 0);		} else {			do_dont_resp[option]++;			send_dont(option, 0);		}	    } else {		/*		 * Option processing that should happen when		 * we receive conformation of a change in		 * state that we had requested.		 */		switch (option) {		case TELOPT_ECHO:			not42 = 0;	/* looks like a 4.2 system */			/*			 * Egads, he responded "WILL ECHO".  Turn			 * it off right now!			 */			send_dont(option, 1);			/*			 * "WILL ECHO".  Kludge upon kludge!			 * A 4.2 client is now echoing user input at			 * the tty.  This is probably undesireable and			 * it should be stopped.  The client will			 * respond WONT TM to the DO TM that we send to			 * check for kludge linemode.  When the WONT TM			 * arrives, linemode will be turned off and a			 * change propogated to the pty.  This change			 * will cause us to process the new pty state			 * in localstat(), which will notice that			 * linemode is off and send a WILL ECHO			 * so that we are properly in character mode and			 * all is well.			 */			break;#ifdef	LINEMODE		case TELOPT_LINEMODE:# ifdef	KLUDGELINEMODE			/*			 * Note client's desire to use linemode.			 */			lmodetype = REAL_LINEMODE;# endif	/* KLUDGELINEMODE */			func = doclientstat;			break;#endif	/* LINEMODE */#ifdef	AUTHENTICATION		case TELOPT_AUTHENTICATION:			func = auth_request;			break;#endif#ifdef	ENCRYPTION		case TELOPT_ENCRYPT:			func = encrypt_send_support;			break;#endif	/* ENCRYPTION */		case TELOPT_LFLOW:			func = flowstat;			break;		}	    }	}	set_his_state_will(option);	if (func)		(*func)();}  /* end of willoption */	voidsend_dont(option, init)	int option, init;{	if (init) {		if ((do_dont_resp[option] == 0 && his_state_is_wont(option)) ||		    his_want_state_is_wont(option))			return;		set_his_want_state_wont(option);		do_dont_resp[option]++;	}	(void) sprintf(nfrontp, (char *)dont, option);	nfrontp += sizeof (doopt) - 2;	DIAG(TD_OPTIONS, printoption("td: send dont", option));}	voidwontoption(option)	int option;{	/*	 * Process client input.	 */	DIAG(TD_OPTIONS, printoption("td: recv wont", option));	if (do_dont_resp[option]) {		do_dont_resp[option]--;		if (do_dont_resp[option] && his_state_is_wont(option))			do_dont_resp[option]--;	}	if (do_dont_resp[option] == 0) {	    if (his_want_state_is_will(option)) {		/* it is always ok to change to negative state */		switch (option) {		case TELOPT_ECHO:			not42 = 1; /* doesn't seem to be a 4.2 system */			break;		case TELOPT_BINARY:			init_termbuf();			tty_binaryin(0);			set_termbuf();			break;#ifdef	LINEMODE		case TELOPT_LINEMODE:# ifdef	KLUDGELINEMODE			/*			 * If real linemode is supported, then client is			 * asking to turn linemode off.			 */			if (lmodetype != REAL_LINEMODE)				break;			lmodetype = KLUDGE_LINEMODE;# endif	/* KLUDGELINEMODE */			clientstat(TELOPT_LINEMODE, WONT, 0);			break;#endif	/* LINEMODE */		case TELOPT_TM:			/*			 * If we get a WONT TM, and had sent a DO TM,			 * don't respond with a DONT TM, just leave it			 * as is.  Short circut the state machine to			 * achive this.			 */			set_his_want_state_wont(TELOPT_TM);			return;		case TELOPT_LFLOW:			/*			 * If we are not going to support flow control			 * option, then let peer know that we can't			 * change the flow control characters.			 */			slctab[SLC_XON].defset.flag &= ~SLC_LEVELBITS;			slctab[SLC_XON].defset.flag |= SLC_CANTCHANGE;			slctab[SLC_XOFF].defset.flag &= ~SLC_LEVELBITS;			slctab[SLC_XOFF].defset.flag |= SLC_CANTCHANGE;			break;#if	defined(AUTHENTICATION)		case TELOPT_AUTHENTICATION:			auth_finished(0, AUTH_REJECT);			break;#endif		/*		 * For options that we might spin waiting for		 * sub-negotiation, if the client turns off the		 * option rather than responding to the request,		 * we have to treat it here as if we got a response		 * to the sub-negotiation, (by updating the timers)		 * so that we'll break out of the loop.		 */		case TELOPT_TTYPE:			settimer(ttypesubopt);			break;		case TELOPT_TSPEED:			settimer(tspeedsubopt);			break;		case TELOPT_XDISPLOC:			settimer(xdisplocsubopt);			break;		case TELOPT_OLD_ENVIRON:			settimer(oenvironsubopt);			break;		case TELOPT_NEW_ENVIRON:			settimer(environsubopt);			break;		default:			break;		}		set_his_want_state_wont(option);		if (his_state_is_will(option))			send_dont(option, 0);	    } else {		switch (option) {		case TELOPT_TM:#if	defined(LINEMODE) && defined(KLUDGELINEMODE)			if (lmodetype < NO_AUTOKLUDGE) {				lmodetype = NO_LINEMODE;				clientstat(TELOPT_LINEMODE, WONT, 0);				send_will(TELOPT_SGA, 1);				send_will(TELOPT_ECHO, 1);			}#endif	/* defined(LINEMODE) && defined(KLUDGELINEMODE) */			break;#if	defined(AUTHENTICATION)		case TELOPT_AUTHENTICATION:			auth_finished(0, AUTH_REJECT);			break;#endif		default:			break;		}	    }	}	set_his_state_wont(option);}  /* end of wontoption */	voidsend_will(option, init)	int option, init;{	if (init) {		if ((will_wont_resp[option] == 0 && my_state_is_will(option))||		    my_want_state_is_will(option))			return;		set_my_want_state_will(option);		will_wont_resp[option]++;	}	(void) sprintf(nfrontp, (char *)will, option);	nfrontp += sizeof (doopt) - 2;	DIAG(TD_OPTIONS, printoption("td: send will", option));}#if	!defined(LINEMODE) || !defined(KLUDGELINEMODE)/* * When we get a DONT SGA, we will try once to turn it * back on.  If the other side responds DONT SGA, we * leave it at that.  This is so that when we talk to * clients that understand KLUDGELINEMODE but not LINEMODE, * we'll keep them in char-at-a-time mode. */int turn_on_sga = 0;#endif	voiddooption(option)	int option;{	int changeok = 0;	/*	 * Process client input.	 */	DIAG(TD_OPTIONS, printoption("td: recv do", option));	if (will_wont_resp[option]) {		will_wont_resp[option]--;		if (will_wont_resp[option] && my_state_is_will(option))			will_wont_resp[option]--;	}	if ((will_wont_resp[option] == 0) && (my_want_state_is_wont(option))) {		switch (option) {		case TELOPT_ECHO:#ifdef	LINEMODE# ifdef	KLUDGELINEMODE			if (lmodetype == NO_LINEMODE)# else			if (his_state_is_wont(TELOPT_LINEMODE))# endif#endif			{				init_termbuf();				tty_setecho(1);				set_termbuf();			}			changeok++;			break;		case TELOPT_BINARY:			init_termbuf();			tty_binaryout(1);			set_termbuf();			changeok++;			break;		case TELOPT_SGA:#if	defined(LINEMODE) && defined(KLUDGELINEMODE)			/*			 * If kludge linemode is in use, then we must			 * process an incoming do SGA for linemode			 * purposes.			 */			if (lmodetype == KLUDGE_LINEMODE) {				/*				 * Receipt of "do SGA" in kludge				 * linemode is the peer asking us to				 * turn off linemode.  Make note of				 * the request.				 */				clientstat(TELOPT_LINEMODE, WONT, 0);				/*				 * If linemode did not get turned off				 * then don't tell peer that we did.				 * Breaking here forces a wont SGA to				 * be returned.				 */				if (linemode)					break;			}#else			turn_on_sga = 0;#endif	/* defined(LINEMODE) && defined(KLUDGELINEMODE) */			changeok++;			break;		case TELOPT_STATUS:			changeok++;			break;		case TELOPT_TM:			/*			 * Special case for TM.  We send a WILL, but			 * pretend we sent a WONT.			 */			send_will(option, 0);			set_my_want_state_wont(option);			set_my_state_wont(option);			return;		case TELOPT_LOGOUT:			/*			 * When we get a LOGOUT option, respond			 * with a WILL LOGOUT, make sure that			 * it gets written out to the network,			 * and then just go away...			 */			set_my_want_state_will(TELOPT_LOGOUT);			send_will(TELOPT_LOGOUT, 0);			set_my_state_will(TELOPT_LOGOUT);			(void)netflush();			cleanup(0);			/* NOT REACHED */			break;#ifdef	ENCRYPTION		case TELOPT_ENCRYPT:			changeok++;			break;#endif	/* ENCRYPTION */		case TELOPT_LINEMODE:		case TELOPT_TTYPE:		case TELOPT_NAWS:		case TELOPT_TSPEED:		case TELOPT_LFLOW:		case TELOPT_XDISPLOC:#ifdef	TELOPT_ENVIRON		case TELOPT_NEW_ENVIRON:#endif		case TELOPT_OLD_ENVIRON:		default:			break;		}		if (changeok) {			set_my_want_state_will(option);			send_will(option, 0);		} else {			will_wont_resp[option]++;			send_wont(option, 0);		}	}	set_my_state_will(option);}  /* end of dooption */	voidsend_wont(option, init)	int option, init;{	if (init) {		if ((will_wont_resp[option] == 0 && my_state_is_wont(option)) ||		    my_want_state_is_wont(option))			return;		set_my_want_state_wont(option);		will_wont_resp[option]++;	}	(void) sprintf(nfrontp, (char *)wont, option);	nfrontp += sizeof (wont) - 2;	DIAG(TD_OPTIONS, printoption("td: send wont", option));}	voiddontoption(option)	int option;{	/*	 * Process client input.	 */	DIAG(TD_OPTIONS, printoption("td: recv dont", option));	if (will_wont_resp[option]) {		will_wont_resp[option]--;		if (will_wont_resp[option] && my_state_is_wont(option))			will_wont_resp[option]--;	}	if ((will_wont_resp[option] == 0) && (my_want_state_is_will(option))) {		switch (option) {		case TELOPT_BINARY:			init_termbuf();			tty_binaryout(0);			set_termbuf();			break;		case TELOPT_ECHO:	/* we should stop echoing */#ifdef	LINEMODE# ifdef	KLUDGELINEMODE			if ((lmodetype != REAL_LINEMODE) &&			    (lmodetype != KLUDGE_LINEMODE))# else			if (his_state_is_wont(TELOPT_LINEMODE))# endif#endif			{				init_termbuf();				tty_setecho(0);				set_termbuf();			}			break;		case TELOPT_SGA:#if	defined(LINEMODE) && defined(KLUDGELINEMODE)			/*			 * If kludge linemode is in use, then we			 * must process an incoming do SGA for			 * linemode purposes.			 */			if ((lmodetype == KLUDGE_LINEMODE) ||			    (lmodetype == KLUDGE_OK)) {				/*				 * The client is asking us to turn				 * linemode on.				 */				lmodetype = KLUDGE_LINEMODE;				clientstat(TELOPT_LINEMODE, WILL, 0);				/*				 * If we did not turn line mode on,				 * then what do we say?  Will SGA?				 * This violates design of telnet.				 * Gross.  Very Gross.				 */			}			break;#else			set_my_want_state_wont(option);			if (my_state_is_will(option))				send_wont(option, 0);			set_my_state_wont(option);			if (turn_on_sga ^= 1)				send_will(option, 1);			return;#endif	/* defined(LINEMODE) && defined(KLUDGELINEMODE) */		default:			break;		}		set_my_want_state_wont(option);		if (my_state_is_will(option))			send_wont(option, 0);	}	set_my_state_wont(option);}  /* end of dontoption */#ifdef	ENV_HACKint env_ovar = -1;int env_ovalue = -1;#else	/* ENV_HACK */# define env_ovar OLD_ENV_VAR# define env_ovalue OLD_ENV_VALUE#endif	/* ENV_HACK */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -