Exemple #1
0
/*
 Receive sequence -- see if expected response comes return success
 (or failure) in got_it
*/ 
static 
recvSeq()  {
   
    char *e, got[7], trace[SBUFL];
    int i, l;
    
	sequenc();
	l = strlen(e=seq_buf);		/* no more than 7 chars allowed */
	if (l > 7) {
	    e += l-7;
	    l = 7;
	}
	tlog(F111,"expecting sequence",e,(long) l);
	if (l == 0) {		/* null sequence, just delay a little */
	    sleep (NULL_EXP);
	    got_it = 1;
	    tlog(F100,"got it (null sequence)","",0l);
	    return;
	}
	*trace = '\0';
	for (i=0; i<7; i++) got[i]='\0';

	signal(SIGALRM,scrtime);	/* did we get it? */
	if (!setjmp(alrmRng)) {	/* not timed out yet */
	    alarm(EXP_ALRM);
	    while (!got_it) {
		for (i=0; i<(l-1); i++) got[i] = got[i+1]; /* shift over one */
		got[l-1] = ttinc(0) & 0177;		/* next char */
		if (seslog) 		/* Log in session log */
		  zchout(ZSFILE,got[l-1]);
		if (strlen(trace) < sizeof(trace)-2 ) 
		  strcat(trace,chstr(got[l-1]));
		got_it = (!strncmp(seq_buf, got, l) ) ;
	    }
	} else got_it = 0;		/* timed out here */

	alarm(0);
	signal(SIGALRM,SIG_IGN);
	tlog(F110,"received sequence: ",trace,0l);
	tlog(F101,"returning with got-it code","",(long) got_it);
	return;
}
Exemple #2
0
int
qnxinc(void)
{
    extern int pmask, cmask;
    extern int tt_utf8;
    int ch;

  loop:
    ch = ttinc(0);
    if ( ch < 0 )
        return ch;

    if ( seslog )
        logchar(ch);

    /* Handle the UTF8 conversion if we are in that mode */
    if ( tt_utf8 ) {
        USHORT * ucs2 = NULL;
        int rc = utf8_to_ucs2( (CHAR)(ch & 0xFF), &ucs2 );
        if ( rc > 0 )
            goto loop;
        else if ( rc < 0 )
            ch = 0xfffd;
        else
            ch = *ucs2;
    }

    if ( !xprint ) {
#ifndef NOXFER
        autodown(ch);
#endif /* NOXFER */
        autoexitchk(ch);
    }
    ch = ch & pmask & cmask;
    debugses(ch);
    if (printon && (is_xprint() || is_uprint()))
        prtchar(ch);
    return ch;
}
Exemple #3
0
unsigned  sytek_int( unsigned ax /*, unsigned dx */ )
{
    unsigned char ah;
    unsigned char ch;
/*    int sent; */
    unsigned int status;


    if ( !s ) {
        return( 0x1000 );   /* timeout */
    }

    if (chk_timeout( recvtimeout )) {
        do_reception();
        recvtimeout = set_ttimeout( 2 );    /* 10 ms */
    }

    /* disable(); receive_clock = RECEIVE_TICKS; enable(); } */

    ah = ax >> 8;

    if( ah == 1 ) {			/* send char in AL */
	ch = ax & 0x0FF;
/*	if (ch == '\r') ch = '\n'; */

	if( ((tran_in + 1) % TRANSMIT_BUF_SIZE) == tran_out ) {
	    outs( "?tr_buf_full?" );
	    status = 0x08000 | ch;
	} else {
	    if ((ch == '\r') && echo ) stuff_char( '\n' );
	    else stuff_char( ch );

	    status = 0x06000 | ch;

	    /* local echoing if requested */
	    if ( echo ) {
		receive_buffer[ rec_in ] = ch;
		rec_in = (rec_in + 1) % RECEIVE_BUF_SIZE;
		if (ch == '\r') {
		    receive_buffer[ rec_in ] = '\n';
		    rec_in = (rec_in + 1) % RECEIVE_BUF_SIZE;
		}
	    }
	}
    } else if( ah == 2 ) {		/* receive char into AL */
        do {
            ch = 0;
            if( rec_in == rec_out )
	        status = 0x08000;
            else {
		status = ch = (ttinc( 0 ) & 0xff);
                if ( ch == IAC ) {
                    /* process this stuff */
		    ch = ttinc( 0 );
                    if ( ch == IAC ) ch = 0; /* let it pass through */
		    else tn_doop(ch);
                }
            }
	} while ( ch == IAC );
	/* status = 0x0800; timeout */
    }
    else if( ah == 3 ) {		/* get status */
	if( rec_in == rec_out )
	    status = 0x06010;
	else {
	    status = 0x06110;
	}

    } else if( ah == 0 ) {		/* init port */
	status = 0x06010;
    } else {
	status = ax;
	outs( "?command_err?" );
    }

    /* here we do the io */
    if( transmit_clock <= 0 ) {
        do_transmission();
        disable();
        transmit_clock = TRANSMIT_TICKS;
        enable();
    }

    return( status );
}
Exemple #4
0
int tn_doop(int c)
{
    int x, y, n, flag;


    x = ttinc(0) & 0xff;                /* Read command character */

    switch (x) {
      case TELOPT_ECHO:                 /* ECHO negotiation. */
        if (c == WILL) {                /* Host says it will echo. */
	    if (echo) {                 /* Only reply if change required */
		echo = 0;
		if (send_iac(DO,x))  	/* Please do. */
		    return(-1);
	    }
	    return(0);
	}

        if (c == WONT) {                /* Host says it won't echo. */
            if (!echo) {                /* If I'm not echoing already */
		if (send_iac(DONT,x)) /* agree to echo. */
		    return(-1);
		echo = 1;
	    }
	    return(0);
	}

        if (c == DO) {                  /* Host wants me to echo */
	    if (send_iac(WONT,x))	/* I say I won't, */
		return(-1);
	    if (send_iac(DO,x))		/* and ask the host to echo. */
		return(-1);
	    echo = 0;
	    return( 0 );
        }
        if (c == DONT) {                /* Host wants me not to echo */
	    if (send_iac(WONT,x))	/* I say I won't. */
		return(-1);
	    echo = 0;
	    return( 0 );
        }
        return(0);


      case TELOPT_SGA:                  /* Suppress Go-Ahead */
        if (c == WONT) {                /* Host says it won't. */
            sgaflg = 1;                 /* Remember. */
            if (!echo) {                /* If we're not echoing, */
		if (send_iac(DONT,x)) /* acknowledge, */
		    return(-1);
		echo = 1;		/* and switch to local echo. */
	    }
        }
        if (c == WILL) {                /* Host says it will. */
            sgaflg = 0;                 /* Remember. */
            if (echo) {                 /* If I'm echoing now, */
		if (send_iac(DO,x))	/* this is a change, so ACK. */
		    return(-1);
		if (send_iac(DO,TELOPT_ECHO)) /* Request remote echo */
		    return(-1);
            }
        }
        return(0);


      case TELOPT_TTYPE:                /* Terminal Type */
        switch (c) {
          case DO:                      /* DO terminal type. */
	    if (send_iac(WILL,x))    /* Say I'll send it if asked. */
		return(-1);
	    return(0);

	  /* enter subnegociations */
          case SB:
            n = flag = 0;               /* Flag for when done reading SB */
            while (n < TSBUFSIZ) {      /* Loop looking for IAC SE */
                if ((y = ttinc(0)) < 0)
		  return(-1);
		y &= 0xff;              /* Make sure it's just 8 bits. */
		sb[n++] = y;            /* Save what we got in buffer. */

                if (y == IAC) {         /* If this is an IAC */
                    flag = 1;           /* set the flag. */
                } else {                /* Otherwise, */
                    if (flag && y == SE) /* if this is SE which immediately */
                      break;            /* follows IAC, we're done. */
                    else flag = 0;      /* Otherwise turn off flag. */
                }
	    }
	    if (!flag)
	       return(-1);      /* Make sure we got a valid SB */


	    if ( *sb == 1 ) {
		if ( tn_sttyp() )
                  return(-1);
	    };


          default:                      /* Others, ignore */
            return(0);
        }

      default:                          /* All others: refuse */
        switch(c) {
          case WILL:                    /* You will? */
	    if (send_iac(DONT,x))	/* Please don't. */
		return(-1);
            break;
          case DO:                      /* You want me to? */
	    if (send_iac(WONT,x))	/* I won't. */
		return(-1);
	    if (send_iac(DONT,x))	/* Don't you either. */
		return(-1);
            break;
          case DONT:                    /* (fall thru...) */
	    if (send_iac(WONT,x))	/* I won't. */
		return(-1);
          case WONT:                    /* You won't? */
            break;                      /* Good. */
          }
        return(0);
    }
}