Пример #1
0
ssize_t forward(rlyinfo *ri)
{
  settimer(TIMEOUTSEC);
  readn(ri);
  if (ri->nread > 0) {
    ri->nw = ri->nread;
    writen(ri);
  }
  settimer(0);
  if (ri->nread == 0)
    return(0);           /* EOF */
  if (ri->nread < 0)
    return(-1);
  return(ri->nwritten);
}
void CassandraConnectionChannel::write_handler(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t bytes_written,  apache::thrift::transport::TMemoryBuffer* message, const VoidCallback& cob){
  updateTimerContext();
  if (error){
    handleError(error);
    return;
  }
  
  //get message size
  uint32_t size;
  uint8_t* bufPtr;
  message->getBuffer(&bufPtr, &size);

  bytes_written += bytes_transferred;
  
  if (bytes_written == size){
    //we are done writing
    m_Timer.cancel();
    cob();
    return;
  }
  
  //we need to continue
  bufPtr += bytes_written;
  m_Socket.async_write_some(boost::asio::buffer(bufPtr, size-bytes_written),
			    boost::bind(& CassandraConnectionChannel::write_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					bytes_written,
					message,
					cob));

  settimer(m_IOTimeoutms);
}
Пример #3
0
static int
getterminaltype (void)
{
  int retval = -1;

  settimer(baseline);

  send_do(TELOPT_TTYPE, 1);
  send_do(TELOPT_TSPEED, 1);
  send_do(TELOPT_XDISPLOC, 1);
  send_do(TELOPT_ENVIRON, 1);
  while (his_will_wont_is_changing(TELOPT_TTYPE) ||
	 his_will_wont_is_changing(TELOPT_TSPEED) ||
	 his_will_wont_is_changing(TELOPT_XDISPLOC) ||
	 his_will_wont_is_changing(TELOPT_ENVIRON)) {
    ttloop();
  }

  if (his_state_is_will(TELOPT_TSPEED)) {
    static unsigned char sb[] =
    { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };

    memmove((void *)nfrontp, (void *)sb, sizeof sb);
    nfrontp += sizeof sb;
    DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
  }
void CassandraConnectionChannel::read_message_handler(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t bytes_to_read,  apache::thrift::transport::TMemoryBuffer* message, const VoidCallback& cob){
  updateTimerContext();
  if (error){
    handleError(error);
    return;
  }

  bytes_to_read -= bytes_transferred;
  message->wroteBytes(bytes_transferred);
  
  if (bytes_to_read){
    //we are not done, continue
    uint8_t* bufPtr = message->getWritePtr(bytes_to_read);
    
    m_Socket.async_read_some(boost::asio::buffer(bufPtr, bytes_to_read),
			     boost::bind(& CassandraConnectionChannel::read_message_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					bytes_to_read,
					message,
					cob));

    settimer(m_IOTimeoutms);    
    
    return;
  }

  //we are done.
  m_Timer.cancel();
  cob();
}
Пример #5
0
int main() {
	int serial, control, fd, timel, timeu, ticks, bitset;
	bitset = TIOCM_DTR;	//Mask For the DTR Pin bit
	setupPort43();		//Sets up Port43
	settimer();		//Sets up Timer(port42) and starts it
	fd = open("/dev/ttyUSB0", O_RDWR);	//Opens the Serial port
	if(fd == -1){		//Error Checking
   	 	printf("Could Not Open Serial Port");
		exit(1);
  	}
	while(1){
		ioctl(fd, TIOCMGET, &serial);	//Ioctl using TIOCMGET
								//Reads from the serial 
//port and places in serial
		if((serial & TIOCM_RI) == TIOCM_RI) control = 3750;
		else control = 256;
		timel = inb(0x42);
		timeu = inb(0x42);
		ticks = (timeu << 8) + timel;
		if(ticks >= control) ioctl(fd, TIOCMSET, &bitset);
		else ioctl(fd, TIOCMSET, &bitset);
		//Turns LED on and off
		printf("%d\n", control);
		
	}
	close(fd);
	return 0;
}
Пример #6
0
void transfer(struct thread_queue_struct * mthread)
#endif
{
#ifndef WITH_REALTIME_THREADS
  struct thread_list *tl;
  machdep_save_float_state(&(gtl->mthread));
  if (machdep_save_state(&(gtl->mthread))) {
    return;
  }
#else
  /* if the transfer thread is the current thread, just return */
#ifdef RTJ_DEBUG_THREADS
  printf("\nTransfer from %p to %p", currentThread, mthread);
  fflush(NULL);
#endif
  if(mthread == currentThread) {
    settimer();
    return;
  }

  /* if there is currently a thread running, save it's state */
  if(currentThread != NULL) {
    machdep_save_float_state(currentThread->mthread);
    if (machdep_save_state(currentThread->mthread)) {
#ifdef RTJ_DEBUG_THREADS
      printf(" returning directly!");
      fflush(NULL);
#endif
      return;
    }
  }
#endif

#ifndef WITH_REALTIME_THREADS
  tl=gtl;
  tl->prev->next=tl->next;
  tl->next->prev=tl->prev;
  if (tl!=tl->next) {
    gtl=gtl->next;
  } else {
    gtl=NULL;
  }
  
  if (ioptr!=NULL) {
    tl->next=ioptr;
    tl->prev=ioptr->prev;
    tl->next->prev=tl;
    tl->prev->next=tl;
  } else {
    ioptr=tl;
    tl->next=tl;
    tl->prev=tl;
  }
  startnext();
#else
  currentThread = mthread; //set the transfer thread to be the current thread
  restorethread(); //switch to it#
#endif
}
Пример #7
0
int
getterminaltype(char *name, size_t name_sz)
{
    int retval = -1;

    settimer(baseline);
#ifdef AUTHENTICATION
    /*
     * Handle the Authentication option before we do anything else.
     */
    send_do(TELOPT_AUTHENTICATION, 1);
    while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
	ttloop();
    if (his_state_is_will(TELOPT_AUTHENTICATION)) {
	retval = auth_wait(name, name_sz);
    }
#endif

#ifdef ENCRYPTION
    send_will(TELOPT_ENCRYPT, 1);
    send_do(TELOPT_ENCRYPT, 1);	/* [email protected] */
#endif
    /* DayDream wants binary transmission mode */
    send_will(TELOPT_BINARY, 1);
    send_do(TELOPT_BINARY, 1);
    send_do(TELOPT_TTYPE, 1);
    send_do(TELOPT_TSPEED, 1);
    send_do(TELOPT_XDISPLOC, 1);
    send_do(TELOPT_NEW_ENVIRON, 1);
    send_do(TELOPT_OLD_ENVIRON, 1);
    while (
#ifdef ENCRYPTION
	   his_do_dont_is_changing(TELOPT_ENCRYPT) ||
#endif
	   his_do_dont_is_changing(TELOPT_BINARY) ||
	   his_will_wont_is_changing(TELOPT_TTYPE) ||
	   his_will_wont_is_changing(TELOPT_TSPEED) ||
	   his_will_wont_is_changing(TELOPT_XDISPLOC) ||
	   his_will_wont_is_changing(TELOPT_NEW_ENVIRON) ||
	   his_will_wont_is_changing(TELOPT_OLD_ENVIRON)) {
	ttloop();
    }
#ifdef ENCRYPTION
    /*
     * Wait for the negotiation of what type of encryption we can
     * send with.  If autoencrypt is not set, this will just return.
     */
    if (his_state_is_will(TELOPT_ENCRYPT)) {
	encrypt_wait();
    }
#endif
    if (his_state_is_will(TELOPT_BINARY)) {
	static unsigned char sb[] =
	{ IAC, SB, TELOPT_BINARY, TELQUAL_SEND, IAC, SE };

	telnet_net_write (sb, sizeof sb);
	DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2););
    }
void CassandraConnectionChannel::connect(const boost::asio::ip::tcp::endpoint& endpoint, int connectTimeoutms, const VoidCallback& cob){
  
  //connect
  m_Socket.async_connect(endpoint, 
			 boost::bind(&CassandraConnectionChannel::connect_handler, 
				     shared_from_this(), 
				     boost::asio::placeholders::error, 
				     cob));
  settimer(connectTimeoutms);
}
Пример #9
0
void restorethread() {
  /* 
   * Restore the threads state.
   */
#ifdef WITH_REALTIME_THREADS
  settimer();
#endif
  machdep_restore_float_state();
  machdep_restore_state();
}
Пример #10
0
int showcaret(HWND hwnd, int x, int y) {
    int o; POINT pt;
    pt.x = x; pt.y = y;
    ScreenToClient(hwnd,&pt);
    o=getmoupos(pt.x,pt.y);
    if (o!=-1) {
        setcaret(hwnd);
        return 0;
    }
    settimer(hwnd,0,SCROLL_INTERVAL);
    return 1;
}
/*override*/ 
void CassandraConnectionChannel::recvMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message){
  settimer(m_ReplyTimeoutms);

  m_Socket.async_read_some(boost::asio::buffer(&m_Insize, 4),
			    boost::bind(& CassandraConnectionChannel::read_size_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					4,
					message,
					cob));
}
Пример #12
0
static void
willoption(int option)
{
	int new_state_ok = 0;

	if (do_dont_resp[option]) {
	    --do_dont_resp[option];
	    if (do_dont_resp[option] && my_state_is_do(option))
		--do_dont_resp[option];
	}

	if ((do_dont_resp[option] == 0) && my_want_state_is_dont(option)) {

	    switch (option) {

	    case TELOPT_ECHO:
	    case TELOPT_BINARY:
	    case TELOPT_SGA:
		settimer(modenegotiated);
		/* FALL THROUGH */
	    case TELOPT_STATUS:
		new_state_ok = 1;
		break;

	    case TELOPT_TM:
		if (flushout)
		    flushout = 0;
		/*
		 * Special case for TM.  If we get back a WILL,
		 * pretend we got back a WONT.
		 */
		set_my_want_state_dont(option);
		set_my_state_dont(option);
		return;			/* Never reply to TM will's/wont's */

	    case TELOPT_LINEMODE:
	    default:
		break;
	    }

	    if (new_state_ok) {
		set_my_want_state_do(option);
		send_do(option, 0);
		setconnmode(0);		/* possibly set new tty mode */
	    } else {
		do_dont_resp[option]++;
		send_dont(option, 0);
	    }
	}
	set_my_state_do(option);

}
Пример #13
0
void
wontoption(int option)
{
	if (do_dont_resp[option]) {
	    --do_dont_resp[option];
	    if (do_dont_resp[option] && my_state_is_dont(option))
		--do_dont_resp[option];
	}

	if ((do_dont_resp[option] == 0) && my_want_state_is_do(option)) {

	    switch (option) {

#ifdef	KLUDGELINEMODE
	    case TELOPT_SGA:
		if (!kludgelinemode)
		    break;
		/* FALL THROUGH */
#endif
	    case TELOPT_ECHO:
		settimer(modenegotiated);
		break;

	    case TELOPT_TM:
		if (flushout)
		    flushout = 0;
		set_my_want_state_dont(option);
		set_my_state_dont(option);
		return;		/* Never reply to TM will's/wont's */

#ifdef ENCRYPTION
  	    case TELOPT_ENCRYPT:
	      encrypt_not();
	      break;
#endif
	    default:
		break;
	    }
	    set_my_want_state_dont(option);
	    if (my_state_is_do(option))
		send_dont(option, 0);
	    setconnmode(0);			/* Set new tty mode */
	} else if (option == TELOPT_TM) {
	    /*
	     * Special case for TM.
	     */
	    if (flushout)
		flushout = 0;
	    set_my_want_state_dont(option);
	}
	set_my_state_dont(option);
}
Пример #14
0
// ===================================
// timersignal...
// -----------------------------------
void timersignal(void) {
	int pid;
	int val;
	switch (tpid = fork()) {
	case 0:
	signal(SIGUSR2,resettimer);
	settimer(timeout);
	pid = getppid();
	while(1) {
		val = gettimer(); sleep(1);
		kill (pid,SIGTRAP);
	}
	}
}
Пример #15
0
static void
_gettermname(void)
{
    /*
     * If the client turned off the option,
     * we can't send another request, so we
     * just return.
     */
    if (his_state_is_wont(TELOPT_TTYPE))
	return;
    settimer(baseline);
    netoprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE);
    while (sequenceIs(ttypesubopt, baseline))
	ttloop();
}
Пример #16
0
static
void
_gettermname(void)
{
    /*
     * If the client turned off the option,
     * we can't send another request, so we
     * just return.
     */
    if (his_state_is_wont(TELOPT_TTYPE))
	return;
    settimer(baseline);
    bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
    nfrontp += sizeof ttytype_sbbuf;
    while (sequenceIs(ttypesubopt, baseline))
	ttloop();
}
/*override*/ 
void CassandraConnectionChannel::sendMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message){
  //set message size
  uint32_t size;
  uint8_t* bufPtr;
  message->getBuffer(&bufPtr, &size);
  uint32_t* frameSize = reinterpret_cast<uint32_t*>(bufPtr);
  *frameSize = htonl(size-4);

  settimer(m_IOTimeoutms);

  m_Socket.async_write_some(boost::asio::buffer(bufPtr, size),
			    boost::bind(& CassandraConnectionChannel::write_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					0,
					message,
					cob));
}
void CassandraConnectionChannel::read_size_handler(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t bytes_to_read,  apache::thrift::transport::TMemoryBuffer* message, const VoidCallback& cob){
  updateTimerContext();
  if (error){
    handleError(error);
    return;
  }

  settimer(m_IOTimeoutms);
  
  bytes_to_read -= bytes_transferred;
  if (!bytes_to_read){
    //we are done, read the message itself
    m_Insize = ntohl(m_Insize);
    uint8_t* bufPtr = message->getWritePtr(m_Insize);
    

    m_Socket.async_read_some(boost::asio::buffer(bufPtr, m_Insize),
			     boost::bind(& CassandraConnectionChannel::read_message_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					m_Insize,
					message,
					cob));
    return;
  }

  //need to read more
  uint8_t* bufPtr = reinterpret_cast<uint8_t*>(&m_Insize);
  bufPtr+= (4-bytes_to_read);
  m_Socket.async_read_some(boost::asio::buffer(bufPtr, bytes_to_read),
			   boost::bind(& CassandraConnectionChannel::read_size_handler, 
					shared_from_this(), 
					boost::asio::placeholders::error,
					boost::asio::placeholders::bytes_transferred,
					bytes_to_read,
				        message,
					cob));
}
Пример #19
0
void wontoption(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(AUTHENTICATE)
            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_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 < REAL_LINEMODE) {
                    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(AUTHENTICATE)
            case TELOPT_AUTHENTICATION:
                auth_finished(0, AUTH_REJECT);
                break;
#endif
            default:
                break;
            }
        }
    }
}  /* end of wontoption */
Пример #20
0
static
int
getterminaltype(char *name)
{
    int retval = -1;
    (void)name;

    settimer(baseline);
#if defined(AUTHENTICATE)
    /*
     * Handle the Authentication option before we do anything else.
     */
    send_do(TELOPT_AUTHENTICATION, 1);
    while (his_will_wont_is_changing(TELOPT_AUTHENTICATION))
	ttloop();
    if (his_state_is_will(TELOPT_AUTHENTICATION)) {
	retval = auth_wait(name);
    }
#endif

#if	defined(ENCRYPT)
    send_will(TELOPT_ENCRYPT, 1);
#endif
    send_do(TELOPT_TTYPE, 1);
    send_do(TELOPT_TSPEED, 1);
    send_do(TELOPT_XDISPLOC, 1);
    send_do(TELOPT_ENVIRON, 1);
    while (
#if	defined(ENCRYPT)
	   his_do_dont_is_changing(TELOPT_ENCRYPT) ||
#endif
	   his_will_wont_is_changing(TELOPT_TTYPE) ||
	   his_will_wont_is_changing(TELOPT_TSPEED) ||
	   his_will_wont_is_changing(TELOPT_XDISPLOC) ||
	   his_will_wont_is_changing(TELOPT_ENVIRON)) {
	ttloop();
    }
#if	defined(ENCRYPT)
    /*
     * Wait for the negotiation of what type of encryption we can
     * send with.  If autoencrypt is not set, this will just return.
     */
    if (his_state_is_will(TELOPT_ENCRYPT)) {
	encrypt_wait();
    }
#endif
    if (his_state_is_will(TELOPT_TSPEED)) {
	static char sbbuf[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE };

	bcopy(sbbuf, nfrontp, sizeof sbbuf);
	nfrontp += sizeof sbbuf;
    }
    if (his_state_is_will(TELOPT_XDISPLOC)) {
	static char sbbuf[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE };

	bcopy(sbbuf, nfrontp, sizeof sbbuf);
	nfrontp += sizeof sbbuf;
    }
    if (his_state_is_will(TELOPT_ENVIRON)) {
	static char sbbuf[] = { IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE };

	bcopy(sbbuf, nfrontp, sizeof sbbuf);
	nfrontp += sizeof sbbuf;
    }
    if (his_state_is_will(TELOPT_TTYPE)) {

	bcopy(ttytype_sbbuf, nfrontp, sizeof ttytype_sbbuf);
	nfrontp += sizeof ttytype_sbbuf;
    }
    if (his_state_is_will(TELOPT_TSPEED)) {
	while (sequenceIs(tspeedsubopt, baseline))
	    ttloop();
    }
    if (his_state_is_will(TELOPT_XDISPLOC)) {
	while (sequenceIs(xdisplocsubopt, baseline))
	    ttloop();
    }
    if (his_state_is_will(TELOPT_ENVIRON)) {
	while (sequenceIs(environsubopt, baseline))
	    ttloop();
    }
    if (his_state_is_will(TELOPT_TTYPE)) {
	char first[256], last[256];

	while (sequenceIs(ttypesubopt, baseline))
	    ttloop();

	/*
	 * If the other side has already disabled the option, then
	 * we have to just go with what we (might) have already gotten.
	 */
	if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) {
	    (void) strncpy(first, terminaltype, sizeof(first));
	    for(;;) {
		/*
		 * Save the unknown name, and request the next name.
		 */
		(void) strncpy(last, terminaltype, sizeof(last));
		_gettermname();
		if (terminaltypeok(terminaltype))
		    break;
		if ((strncmp(last, terminaltype, sizeof(last)) == 0) ||
		    his_state_is_wont(TELOPT_TTYPE)) {
		    /*
		     * We've hit the end.  If this is the same as
		     * the first name, just go with it.
		     */
		    if (strncmp(first, terminaltype, sizeof(first)) == 0)
			break;
		    /*
		     * Get the terminal name one more time, so that
		     * RFC1091 compliant telnets will cycle back to
		     * the start of the list.
		     */
		     _gettermname();
		    if (strncmp(first, terminaltype, sizeof(first)) != 0)
			(void) strncpy(terminaltype, first, sizeof(first));
		    break;
		}
	    }
	}
    }
    return(retval);
}  /* end of getterminaltype */
Пример #21
0
void
telrcv()
{
    register int c;
    static int state = TS_DATA;
#if	defined(CRAY2) && defined(UNICOS5)
    char *opfrontp = pfrontp;
#endif

    while (ncc > 0) {
        if ((&ptyobuf[BUFSIZ] - pfrontp) < 2)
            break;
        c = *netip++ & 0377, ncc--;
        switch (state) {

        case TS_CR:
            state = TS_DATA;
            /* Strip off \n or \0 after a \r */
            if ((c == 0) || (c == '\n')) {
                break;
            }
        /* FALL THROUGH */

        case TS_DATA:
            if (c == IAC) {
                state = TS_IAC;
                break;
            }
            /*
             * We now map \r\n ==> \r for pragmatic reasons.
             * Many client implementations send \r\n when
             * the user hits the CarriageReturn key.
             *
             * We USED to map \r\n ==> \n, since \r\n says
             * that we want to be in column 1 of the next
             * printable line, and \n is the standard
             * unix way of saying that (\r is only good
             * if CRMOD is set, which it normally is).
             */
            if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) {
                int nc = *netip;
#ifdef	LINEMODE
                /*
                 * If we are operating in linemode,
                 * convert to local end-of-line.
                 */
                if (linemode && (ncc > 0) && (('\n' == nc) ||
                                              ((0 == nc) && tty_iscrnl())) ) {
                    netip++;
                    ncc--;
                    c = '\n';
                } else
#endif
                {
                    state = TS_CR;
                }
            }
            *pfrontp++ = c;
            break;

        case TS_IAC:
gotiac:
            switch (c) {

            /*
             * Send the process on the pty side an
             * interrupt.  Do this with a NULL or
             * interrupt char; depending on the tty mode.
             */
            case IP:
                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                interrupt();
                break;

            case BREAK:
                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                sendbrk();
                break;

            /*
             * Are You There?
             */
            case AYT:
                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                recv_ayt();
                break;

            /*
             * Abort Output
             */
            case AO:
            {
                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                ptyflush();	/* half-hearted */
                init_termbuf();

                if (slctab[SLC_AO].sptr &&
                        *slctab[SLC_AO].sptr != (cc_t)(_POSIX_VDISABLE)) {
                    *pfrontp++ =
                        (unsigned char)*slctab[SLC_AO].sptr;
                }

                netclear();	/* clear buffer back */
                *nfrontp++ = IAC;
                *nfrontp++ = DM;
                neturg = nfrontp-1; /* off by one XXX */
                DIAG(TD_OPTIONS,
                     printoption("td: send IAC", DM));
                break;
            }

            /*
             * Erase Character and
             * Erase Line
             */
            case EC:
            case EL:
            {
                cc_t ch;

                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                ptyflush();	/* half-hearted */
                init_termbuf();
                if (c == EC)
                    ch = *slctab[SLC_EC].sptr;
                else
                    ch = *slctab[SLC_EL].sptr;
                if (ch != (cc_t)(_POSIX_VDISABLE))
                    *pfrontp++ = (unsigned char)ch;
                break;
            }

            /*
             * Check for urgent data...
             */
            case DM:
                DIAG(TD_OPTIONS,
                     printoption("td: recv IAC", c));
                SYNCHing = stilloob(net);
                settimer(gotDM);
                break;


            /*
             * Begin option subnegotiation...
             */
            case SB:
                state = TS_SB;
                SB_CLEAR();
                continue;

            case WILL:
                state = TS_WILL;
                continue;

            case WONT:
                state = TS_WONT;
                continue;

            case DO:
                state = TS_DO;
                continue;

            case DONT:
                state = TS_DONT;
                continue;
            case EOR:
                if (his_state_is_will(TELOPT_EOR))
                    doeof();
                break;

            /*
             * Handle RFC 10xx Telnet linemode option additions
             * to command stream (EOF, SUSP, ABORT).
             */
            case xEOF:
                doeof();
                break;

            case SUSP:
                sendsusp();
                break;

            case ABORT:
                sendbrk();
                break;

            case IAC:
                *pfrontp++ = c;
                break;
            }
            state = TS_DATA;
            break;

        case TS_SB:
            if (c == IAC) {
                state = TS_SE;
            } else {
                SB_ACCUM(c);
            }
            break;

        case TS_SE:
            if (c != SE) {
                if (c != IAC) {
                    /*
                     * bad form of suboption negotiation.
                     * handle it in such a way as to avoid
                     * damage to local state.  Parse
                     * suboption buffer found so far,
                     * then treat remaining stream as
                     * another command sequence.
                     */

                    /* for DIAGNOSTICS */
                    SB_ACCUM(IAC);
                    SB_ACCUM(c);
                    subpointer -= 2;

                    SB_TERM();
                    suboption();
                    state = TS_IAC;
                    goto gotiac;
                }
                SB_ACCUM(c);
                state = TS_SB;
            } else {
                /* for DIAGNOSTICS */
                SB_ACCUM(IAC);
                SB_ACCUM(SE);
                subpointer -= 2;

                SB_TERM();
                suboption();	/* handle sub-option */
                state = TS_DATA;
            }
            break;

        case TS_WILL:
            willoption(c);
            state = TS_DATA;
            continue;

        case TS_WONT:
            wontoption(c);
            state = TS_DATA;
            continue;

        case TS_DO:
            dooption(c);
            state = TS_DATA;
            continue;

        case TS_DONT:
            dontoption(c);
            state = TS_DATA;
            continue;

        default:
            syslog(LOG_ERR, "telnetd: panic state=%d\n", state);
            printf("telnetd: panic state=%d\n", state);
            exit(1);
        }
    }
#if	defined(CRAY2) && defined(UNICOS5)
    if (!linemode) {
        char	xptyobuf[BUFSIZ+NETSLOP];
        char	xbuf2[BUFSIZ];
        register char *cp;
        int n = pfrontp - opfrontp, oc;
        memmove(xptyobuf, opfrontp, n);
        pfrontp = opfrontp;
        pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP,
                              xbuf2, &oc, BUFSIZ);
        for (cp = xbuf2; oc > 0; --oc)
            if ((*nfrontp++ = *cp++) == IAC)
                *nfrontp++ = IAC;
    }
#endif	/* defined(CRAY2) && defined(UNICOS5) */
}  /* end of telrcv */
Пример #22
0
/*---------------------------------------------------------------*/
void do_mouse(HWND hwnd, DWORD wParam, DWORD lParam, int msg) {

    int o,x,y,n,i;
    static int mox,moy;
    static char mf2;
    static char lf2;

#ifdef NOCAPT
    static char wmf;
    static int  mux,muy;
#endif

    switch (msg) {
    case WM_MOUSEMOVE: //move
        if ((wParam & MK_RBUTTON)!=0) {
#ifdef NOCAPT
            mox=(short)LOWORD(lParam);
            moy=(short)HIWORD(lParam);
            if (wmf==0) {
                wmf=1,mux=mox,muy=moy;
                return;
            }
            MoveWindow(hwnd,wx0+mox-mux,wy0+moy-muy,wxl,wyl,TRUE);
#endif
            return;
        }

        if (clickflag) return;

        if ((wParam & MK_LBUTTON)==0 || edp==NULL) {
            mox=(short)LOWORD(lParam);
            moy=(short)HIWORD(lParam);
            getmouxy(mox,moy,&x,&y);
            if (edp==NULL) i=1;
            else i=inmark(x+clft,y);
            SetCursor(i?pointC:hCurs);
            return;
        }

        if (lf2==0) return;
#ifndef MV_DandD
mm3:
#endif
        if (drag) {
            setdragc(2+(0!=(GetAsyncKeyState(VK_CONTROL)&0x8000)));
        }
        n=((wParam & MK_SHIFT)!=0 || 0==moumrk);
        if (n==0) { mf2=0; goto mm1; }
        if (mf2) goto mm1;
        mf2=1;
        goto mm2;



    case WM_LBUTTONDBLCLK:
        lf2=0;
        if (edp) {
            o=getkword(fpos, tmpbuff);
            if (tmpbuff[0]) {
                ed_cmd(EK_MARK,o, o+strlen(tmpbuff));
                return;
            }
        }
        goto drag_cancel;

    case WM_LBUTTONDOWN:
        lf2=1;
        resetmsg(hwnd);
        if (clickflag && --clickflag) return;

//#ifndef MV_DandD
        SetCapture(hwnd);
//#endif
        n=2;
mm1:
        mox=(short)LOWORD(lParam);
        moy=(short)HIWORD(lParam);
mm2:
        if (edp==NULL) return;

        o=getmoupos(mox,moy);

        if (o) {
            settimer(hwnd,o,SCROLL_INTERVAL);
            return;
        }

        ed_cmd(EK_SETVAR);
        getmouxy(mox,moy,&x,&y);

        if (n==2 && inmark(x+clft,y)) {
#ifndef MV_DandD
            drag=1;
            goto mm3;
#else
            char *get_block(void);
            char *get_vblock(void);
            char *p,*q; int n;
            p=vmark ? get_vblock() : get_block();
            if (p!=NULL) {
                q = m_alloc(entab (NULL, p, n=strlen(p), tabs)+1);
                q[entab (q, p, n, tabs)]=0;
                i=do_drag(q),
                m_free(q);
                m_free(p);
                if (i==1) ed_cmd(KEY_DELETE);
            }
            return;
#endif
        }

        if (drag && linmrk && vmark==0 && fixline(*ma) != fixline(*me))
            curx=0;

        if (drag && n!=2 && dragmove<2) dragmove++;

        if (n==2)    unmark();
        if (drag==0) setvmark(n==1);
        return;


    case WM_LBUTTONUP:
        lf2=0;
        if (dragmove==2) {
            ed_cmd(drag==3 ? EK_DRAG_COPY : EK_DRAG_MOVE);
            SetCursor(hCurs);
        } else
        if (drag) unmark();
drag_cancel:
        mf2=drag=dragmove=0;
        settimer(hwnd,0,0);

#ifndef MV_DandD
        ReleaseCapture();
#endif
        return;


    case WM_RBUTTONDOWN:
#if 0
        if (NULL!=ShortCut) {
        POINT pt;
        GetCursorPos(&pt);
        TrackPopupMenu(ShortCut,TPM_CENTERALIGN|TPM_RIGHTBUTTON,
                pt.x, pt.y ,0,hwnd,NULL
                );
        return;
        }
#endif

#ifdef NOCAPT
        SetCapture(hwnd);
        mox=(short)LOWORD(lParam);
        moy=(short)HIWORD(lParam);
        wmf=1,mux=mox,muy=moy;
#endif
        return;

    case WM_RBUTTONUP:
#ifdef NOCAPT
        wmf=0;
        if (NULL==ShortCut)
            ReleaseCapture();
#endif
        return;
    }
}
Пример #23
0
int
process_rings (int netin, int netout, int netex, int ttyin, int ttyout,
	       int poll)
	/* If poll == 0, then block until something to do */
{
  int c;
  /* One wants to be a bit careful about setting returnValue
   * to one, since a one implies we did some useful work,
   * and therefore probably won't be called to block next
   * time (TN3270 mode only).
   */
  int returnValue = 0;
  static struct timeval TimeValue = { 0, 0 };
  int maxfd = -1;
  int tmp;

  if ((netout || netin || netex) && net > maxfd)
    maxfd = net;
  if (ttyout && tout > maxfd)
    maxfd = tout;
  if (ttyin && tin > maxfd)
    maxfd = tin;
  tmp = howmany (maxfd + 1, NFDBITS) * sizeof (fd_mask);
  if (tmp > fdsn)
    {
      if (ibitsp)
	free (ibitsp);
      if (obitsp)
	free (obitsp);
      if (xbitsp)
	free (xbitsp);
      fdsn = tmp;
      if ((ibitsp = (fd_set *) malloc (fdsn)) == NULL)
	err (1, "malloc");
      if ((obitsp = (fd_set *) malloc (fdsn)) == NULL)
	err (1, "malloc");
      if ((xbitsp = (fd_set *) malloc (fdsn)) == NULL)
	err (1, "malloc");
      memset (ibitsp, 0, fdsn);
      memset (obitsp, 0, fdsn);
      memset (xbitsp, 0, fdsn);
    }

  if (netout)
    FD_SET (net, obitsp);
  if (ttyout)
    FD_SET (tout, obitsp);
  if (ttyin)
    FD_SET (tin, ibitsp);
  if (netin)
    FD_SET (net, ibitsp);
  if (netex)
    FD_SET (net, xbitsp);

  if ((c = select (maxfd + 1, ibitsp, obitsp, xbitsp,
		   (poll == 0) ? (struct timeval *) 0 : &TimeValue)) < 0)
    {
      if (c == -1)
	{
	  /*
	   * we can get EINTR if we are in line mode,
	   * and the user does an escape (TSTP), or
	   * some other signal generator.
	   */
	  if (errno == EINTR)
	    {
	      return 0;
	    }
#	    if defined(TN3270)
	  /*
	   * we can get EBADF if we were in transparent
	   * mode, and the transcom process died.
	   */
	  if (errno == EBADF)
	    {
	      /*
	       * zero the bits (even though kernel does it)
	       * to make sure we are selecting on the right
	       * ones.
	       */
	      memset (ibitsp, 0, fdsn);
	      memset (obitsp, 0, fdsn);
	      memset (xbitsp, 0, fdsn);
	      return 0;
	    }
#	    endif /* defined(TN3270) */
	  /* I don't like this, does it ever happen? */
	  printf ("sleep(5) from telnet, after select\r\n");
	  sleep (5);
	}
      return 0;
    }

  /*
   * Any urgent data?
   */
  if (FD_ISSET (net, xbitsp))
    {
      FD_CLR (net, xbitsp);
      SYNCHing = 1;
      (void) ttyflush (1);	/* flush already enqueued data */
    }

  /*
   * Something to read from the network...
   */
  if (FD_ISSET (net, ibitsp))
    {
      int canread;

      FD_CLR (net, ibitsp);
      canread = ring_empty_consecutive (&netiring);
#if	!defined(SO_OOBINLINE)
      /*
       * In 4.2 (and some early 4.3) systems, the
       * OOB indication and data handling in the kernel
       * is such that if two separate TCP Urgent requests
       * come in, one byte of TCP data will be overlaid.
       * This is fatal for Telnet, but we try to live
       * with it.
       *
       * In addition, in 4.2 (and...), a special protocol
       * is needed to pick up the TCP Urgent data in
       * the correct sequence.
       *
       * What we do is:  if we think we are in urgent
       * mode, we look to see if we are "at the mark".
       * If we are, we do an OOB receive.  If we run
       * this twice, we will do the OOB receive twice,
       * but the second will fail, since the second
       * time we were "at the mark", but there wasn't
       * any data there (the kernel doesn't reset
       * "at the mark" until we do a normal read).
       * Once we've read the OOB data, we go ahead
       * and do normal reads.
       *
       * There is also another problem, which is that
       * since the OOB byte we read doesn't put us
       * out of OOB state, and since that byte is most
       * likely the TELNET DM (data mark), we would
       * stay in the TELNET SYNCH (SYNCHing) state.
       * So, clocks to the rescue.  If we've "just"
       * received a DM, then we test for the
       * presence of OOB data when the receive OOB
       * fails (and AFTER we did the normal mode read
       * to clear "at the mark").
       */
      if (SYNCHing)
	{
	  int atmark;
	  static int bogus_oob = 0, first = 1;

	  ioctl (net, SIOCATMARK, (char *) &atmark);
	  if (atmark)
	    {
	      c = recv (net, netiring.supply, canread, MSG_OOB);
	      if ((c == -1) && (errno == EINVAL))
		{
		  c = recv (net, netiring.supply, canread, 0);
		  if (clocks.didnetreceive < clocks.gotDM)
		    {
		      SYNCHing = stilloob (net);
		    }
		}
	      else if (first && c > 0)
		{
		  /*
		   * Bogosity check.  Systems based on 4.2BSD
		   * do not return an error if you do a second
		   * recv(MSG_OOB).  So, we do one.  If it
		   * succeeds and returns exactly the same
		   * data, then assume that we are running
		   * on a broken system and set the bogus_oob
		   * flag.  (If the data was different, then
		   * we probably got some valid new data, so
		   * increment the count...)
		   */
		  int i;
		  i = recv (net, netiring.supply + c, canread - c, MSG_OOB);
		  if (i == c &&
		      memcmp (netiring.supply, netiring.supply + c, i) == 0)
		    {
		      bogus_oob = 1;
		      first = 0;
		    }
		  else if (i < 0)
		    {
		      bogus_oob = 0;
		      first = 0;
		    }
		  else
		    c += i;
		}
	      if (bogus_oob && c > 0)
		{
		  int i;
		  /*
		   * Bogosity.  We have to do the read
		   * to clear the atmark to get out of
		   * an infinate loop.
		   */
		  i = read (net, netiring.supply + c, canread - c);
		  if (i > 0)
		    c += i;
		}
	    }
	  else
	    {
	      c = recv (net, netiring.supply, canread, 0);
	    }
	}
      else
	{
	  c = recv (net, netiring.supply, canread, 0);
	}
      settimer (didnetreceive);
#else /* !defined(SO_OOBINLINE) */
      c = recv (net, (char *) netiring.supply, canread, 0);
#endif /* !defined(SO_OOBINLINE) */
      if (c < 0 && errno == EWOULDBLOCK)
	{
	  c = 0;
	}
      else if (c <= 0)
	{
	  return -1;
	}
      if (netdata)
	{
	  Dump ('<', netiring.supply, c);
	}
      if (c)
	ring_supplied (&netiring, c);
      returnValue = 1;
    }

  /*
   * Something to read from the tty...
   */
  if (FD_ISSET (tin, ibitsp))
    {
      FD_CLR (tin, ibitsp);
      c = TerminalRead (ttyiring.supply, ring_empty_consecutive (&ttyiring));
      if (c < 0 && errno == EIO)
	c = 0;
      if (c < 0 && errno == EWOULDBLOCK)
	{
	  c = 0;
	}
      else
	{
	  /* EOF detection for line mode!!!! */
	  if ((c == 0) && MODE_LOCAL_CHARS (globalmode) && isatty (tin))
	    {
	      /* must be an EOF... */
	      *ttyiring.supply = termEofChar;
	      c = 1;
	    }
	  if (c <= 0)
	    {
	      return -1;
	    }
	  if (termdata)
	    {
	      Dump ('<', ttyiring.supply, c);
	    }
	  ring_supplied (&ttyiring, c);
	}
      returnValue = 1;		/* did something useful */
    }

  if (FD_ISSET (net, obitsp))
    {
      FD_CLR (net, obitsp);
      returnValue |= netflush ();
    }
  if (FD_ISSET (tout, obitsp))
    {
      FD_CLR (tout, obitsp);
      returnValue |= (ttyflush (SYNCHing | flushout) > 0);
    }

  return returnValue;
}
Пример #24
0
/*===========================================================================*
 *				do_read					     *
 *===========================================================================*/
static ssize_t do_read(devminor_t minor, u64_t UNUSED(position),
	endpoint_t endpt, cp_grant_id_t grant, size_t size, int flags,
	cdev_id_t id)
{
/* A process wants to read from a terminal. */
  tty_t *tp;
  int r;

  if ((tp = line2tty(minor)) == NULL)
	return ENXIO;

  /* Check if there is already a process hanging in a read, check if the
   * parameters are correct, do I/O.
   */
  if (tp->tty_incaller != NONE || tp->tty_inleft > 0)
	return EIO;
  if (size <= 0)
	return EINVAL;

  /* Copy information from the message to the tty struct. */
  tp->tty_incaller = endpt;
  tp->tty_inid = id;
  tp->tty_ingrant = grant;
  assert(tp->tty_incum == 0);
  tp->tty_inleft = size;

  if (!(tp->tty_termios.c_lflag & ICANON) && tp->tty_termios.c_cc[VTIME] > 0) {
	if (tp->tty_termios.c_cc[VMIN] == 0) {
		/* MIN & TIME specify a read timer that finishes the
		 * read in TIME/10 seconds if no bytes are available.
		 */
		settimer(tp, TRUE);
		tp->tty_min = 1;
	} else {
		/* MIN & TIME specify an inter-byte timer that may
		 * have to be cancelled if there are no bytes yet.
		 */
		if (tp->tty_eotct == 0) {
			settimer(tp, FALSE);
			tp->tty_min = tp->tty_termios.c_cc[VMIN];
		}
	}
  }

  /* Anything waiting in the input buffer? Clear it out... */
  in_transfer(tp);
  /* ...then go back for more. */
  handle_events(tp);
  if (tp->tty_inleft == 0)
	return EDONTREPLY;	/* already done */

  /* There were no bytes in the input queue available. */
  if (flags & CDEV_NONBLOCK) {
	tty_icancel(tp);
	r = tp->tty_incum > 0 ? tp->tty_incum : EAGAIN;
	tp->tty_inleft = tp->tty_incum = 0;
	tp->tty_incaller = NONE;
	return r;
  }

  if (tp->tty_select_ops)
	select_retry(tp);

  return EDONTREPLY;		/* suspend the caller */
}
Пример #25
0
int
telrcv(void)
{
    int c;
    int scc;
    unsigned char *sbp;
    int count;
    int returnValue = 0;

    scc = 0;
    count = 0;
    while (TTYROOM() > 2) {
	if (scc == 0) {
	    if (count) {
		ring_consumed(&netiring, count);
		returnValue = 1;
		count = 0;
	    }
	    sbp = netiring.consume;
	    scc = ring_full_consecutive(&netiring);
	    if (scc == 0) {
		/* No more data coming in */
		break;
	    }
	}

	c = *sbp++ & 0xff, scc--; count++;
#ifdef	ENCRYPTION
	if (decrypt_input)
		c = (*decrypt_input)(c);
#endif	/* ENCRYPTION */

	switch (telrcv_state) {

	case TS_CR:
	    telrcv_state = TS_DATA;
	    if (c == '\0') {
		break;	/* Ignore \0 after CR */
	    }
	    else if ((c == '\n') && my_want_state_is_dont(TELOPT_ECHO) && !crmod) {
		TTYADD(c);
		break;
	    }
	    /* Else, fall through */

	case TS_DATA:
	    if (c == IAC) {
		telrcv_state = TS_IAC;
		break;
	    }
		    /*
		     * The 'crmod' hack (see following) is needed
		     * since we can't * set CRMOD on output only.
		     * Machines like MULTICS like to send \r without
		     * \n; since we must turn off CRMOD to get proper
		     * input, the mapping is done here (sigh).
		     */
	    if ((c == '\r') && my_want_state_is_dont(TELOPT_BINARY)) {
		if (scc > 0) {
		    c = *sbp&0xff;
#ifdef	ENCRYPTION
		    if (decrypt_input)
			c = (*decrypt_input)(c);
#endif	/* ENCRYPTION */
		    if (c == 0) {
			sbp++, scc--; count++;
			/* a "true" CR */
			TTYADD('\r');
		    } else if (my_want_state_is_dont(TELOPT_ECHO) &&
					(c == '\n')) {
			sbp++, scc--; count++;
			TTYADD('\n');
		    } else {
#ifdef	ENCRYPTION
			if (decrypt_input)
			    (*decrypt_input)(-1);
#endif	/* ENCRYPTION */

			TTYADD('\r');
			if (crmod) {
				TTYADD('\n');
			}
		    }
		} else {
		    telrcv_state = TS_CR;
		    TTYADD('\r');
		    if (crmod) {
			    TTYADD('\n');
		    }
		}
	    } else {
		TTYADD(c);
	    }
	    continue;

	case TS_IAC:
process_iac:
	    switch (c) {

	    case WILL:
		telrcv_state = TS_WILL;
		continue;

	    case WONT:
		telrcv_state = TS_WONT;
		continue;

	    case DO:
		telrcv_state = TS_DO;
		continue;

	    case DONT:
		telrcv_state = TS_DONT;
		continue;

	    case DM:
		    /*
		     * We may have missed an urgent notification,
		     * so make sure we flush whatever is in the
		     * buffer currently.
		     */
		printoption("RCVD", IAC, DM);
		SYNCHing = 1;
		(void) ttyflush(1);
		SYNCHing = stilloob();
		settimer(gotDM);
		break;

	    case SB:
		SB_CLEAR();
		telrcv_state = TS_SB;
		continue;

	    case IAC:
		TTYADD(IAC);
		break;

	    case NOP:
	    case GA:
	    default:
		printoption("RCVD", IAC, c);
		break;
	    }
	    telrcv_state = TS_DATA;
	    continue;

	case TS_WILL:
	    printoption("RCVD", WILL, c);
	    willoption(c);
	    telrcv_state = TS_DATA;
	    continue;

	case TS_WONT:
	    printoption("RCVD", WONT, c);
	    wontoption(c);
	    telrcv_state = TS_DATA;
	    continue;

	case TS_DO:
	    printoption("RCVD", DO, c);
	    dooption(c);
	    if (c == TELOPT_NAWS) {
		sendnaws();
	    } else if (c == TELOPT_LFLOW) {
		localflow = 1;
		setcommandmode();
		setconnmode(0);
	    }
	    telrcv_state = TS_DATA;
	    continue;

	case TS_DONT:
	    printoption("RCVD", DONT, c);
	    dontoption(c);
	    flushline = 1;
	    setconnmode(0);	/* set new tty mode (maybe) */
	    telrcv_state = TS_DATA;
	    continue;

	case TS_SB:
	    if (c == IAC) {
		telrcv_state = TS_SE;
	    } else {
		SB_ACCUM(c);
	    }
	    continue;

	case TS_SE:
	    if (c != SE) {
		if (c != IAC) {
		    /*
		     * This is an error.  We only expect to get
		     * "IAC IAC" or "IAC SE".  Several things may
		     * have happend.  An IAC was not doubled, the
		     * IAC SE was left off, or another option got
		     * inserted into the suboption are all possibilities.
		     * If we assume that the IAC was not doubled,
		     * and really the IAC SE was left off, we could
		     * get into an infinate loop here.  So, instead,
		     * we terminate the suboption, and process the
		     * partial suboption if we can.
		     */
		    SB_ACCUM(IAC);
		    SB_ACCUM(c);
		    subpointer -= 2;
		    SB_TERM();

		    printoption("In SUBOPTION processing, RCVD", IAC, c);
		    suboption();	/* handle sub-option */
		    telrcv_state = TS_IAC;
		    goto process_iac;
		}
		SB_ACCUM(c);
		telrcv_state = TS_SB;
	    } else {
		SB_ACCUM(IAC);
		SB_ACCUM(SE);
		subpointer -= 2;
		SB_TERM();
		suboption();	/* handle sub-option */
		telrcv_state = TS_DATA;
	    }
	}
    }
    if (count)
	ring_consumed(&netiring, count);
    return returnValue||count;
}
Пример #26
0
// ===================================
// resettimer...
// -----------------------------------
void resettimer(int s) {
	settimer(timeout);
}
Пример #27
0
static int
telsnd(void)
{
    int tcc;
    int count;
    int returnValue = 0;
    unsigned char *tbp;

    tcc = 0;
    count = 0;
    while (NETROOM() > 2) {
	int sc;
	int c;

	if (tcc == 0) {
	    if (count) {
		ring_consumed(&ttyiring, count);
		returnValue = 1;
		count = 0;
	    }
	    tbp = ttyiring.consume;
	    tcc = ring_full_consecutive(&ttyiring);
	    if (tcc == 0) {
		break;
	    }
	}
	c = *tbp++ & 0xff, sc = strip(c), tcc--; count++;
	if (rlogin != _POSIX_VDISABLE) {
		if (bol) {
			bol = 0;
			if (sc == rlogin) {
				local = 1;
				continue;
			}
		} else if (local) {
			local = 0;
			if (sc == '.' || c == termEofChar) {
				bol = 1;
				command(0, "close\n", 6);
				continue;
			}
			if (sc == termSuspChar) {
				bol = 1;
				command(0, "z\n", 2);
				continue;
			}
			if (sc == escape) {
				command(0, tbp, tcc);
				bol = 1;
				count += tcc;
				tcc = 0;
				flushline = 1;
				break;
			}
			if (sc != rlogin) {
				++tcc;
				--tbp;
				--count;
				c = sc = rlogin;
			}
		}
		if ((sc == '\n') || (sc == '\r'))
			bol = 1;
	} else if (escape != _POSIX_VDISABLE && sc == escape) {
	    /*
	     * Double escape is a pass through of a single escape character.
	     */
	    if (tcc && strip(*tbp) == escape) {
		tbp++;
		tcc--;
		count++;
		bol = 0;
	    } else {
		command(0, (char *)tbp, tcc);
		bol = 1;
		count += tcc;
		tcc = 0;
		flushline = 1;
		break;
	    }
	} else
	    bol = 0;
#ifdef	KLUDGELINEMODE
	if (kludgelinemode && (globalmode&MODE_EDIT) && (sc == echoc)) {
	    if (tcc > 0 && strip(*tbp) == echoc) {
		tcc--; tbp++; count++;
	    } else {
		dontlecho = !dontlecho;
		settimer(echotoggle);
		setconnmode(0);
		flushline = 1;
		break;
	    }
	}
#endif
	if (MODE_LOCAL_CHARS(globalmode)) {
	    if (TerminalSpecialChars(sc) == 0) {
		bol = 1;
		break;
	    }
	}
	if (my_want_state_is_wont(TELOPT_BINARY)) {
	    switch (c) {
	    case '\n':
		    /*
		     * If we are in CRMOD mode (\r ==> \n)
		     * on our local machine, then probably
		     * a newline (unix) is CRLF (TELNET).
		     */
		if (MODE_LOCAL_CHARS(globalmode)) {
		    NETADD('\r');
		}
		NETADD('\n');
		bol = flushline = 1;
		break;
	    case '\r':
		if (!crlf) {
		    NET2ADD('\r', '\0');
		} else {
		    NET2ADD('\r', '\n');
		}
		bol = flushline = 1;
		break;
	    case IAC:
		NET2ADD(IAC, IAC);
		break;
	    default:
		NETADD(c);
		break;
	    }
	} else if (c == IAC) {
	    NET2ADD(IAC, IAC);
	} else {
	    NETADD(c);
	}
    }
    if (count)
	ring_consumed(&ttyiring, count);
    return returnValue||count;		/* Non-zero if we did anything */
}
Пример #28
0
LRESULT CALLBACK EditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){

    char bstr[MAX_PATH];
    char *p,c;
    int i,k,n,o,r,f;
    POINT pt;
    struct edvars *ev;

    r = 0;

    //if (domove(GetParent(hwnd),message,wParam,lParam)) return 0;

    switch (message) {
    case WM_COPYDATA:
        if (0x4F4E4242 == ((PCOPYDATASTRUCT)lParam)->dwData)
        {
            char buff[MAX_PATH];
            int line_nr;
            const char *file = (const char*)((PCOPYDATASTRUCT)lParam)->lpData;
            getfile(buff, file, &line_nr);
            set_currentdir(buff);
            LoadFile(buff);
            if (line_nr) {
                ed_cmd(EK_GOTOLINE,line_nr-1);
                //ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
            }

            r = TRUE;
            goto p0r;
        }

        return bbn_receive_data(hwnd, lParam);

    default:
        if (bb_broadcast_msg == message && message)
        {
            if (bb_register(hwnd) && bb_getstyle(hwnd))
               goto reconfig1;
            return 0;
        }
        break;

    case BB_RECONFIGURE:
        if (bb_getstyle(hwnd))
            goto reconfig1;
        return 0;


    reconfig1:
        bb_close_dlg();
        makedlgfont();

    reconfig:
        zy0 = title_h + FRM-1;
        setsize(hwnd);
        new_back();
        InvalidateRect(hwnd, NULL, FALSE);
        return 0;

    case BB_SETSTYLESTRUCT:
    {
        StyleStruct *d = (StyleStruct *)wParam;
        StyleStruct *s = (StyleStruct *)lParam;
        memset(d, 0, sizeof *d);
        memcpy(d, s, sizeof *d);
        break;
    }

    case BB_SETSTYLE:
    {
        char *d = (char *)wParam;
        char *s = (char *)lParam;
        strcpy(d, s);
        break;
    }

    case WM_CREATE:
        zy0 = title_h + FRM-1;
        setsize(ewnd=hwnd);
        dragC  = LoadCursor(hInst,MAKEINTRESOURCE(101));
        dragCp = LoadCursor(hInst,MAKEINTRESOURCE(102));
        pointC = hCurs = LoadCursor(NULL,IDC_ARROW);
        init_edit(hwnd);
        DragAcceptFiles(hwnd,TRUE);
        if (false == bb_register(hwnd) || false == bb_getstyle(hwnd))
            readstyle(defstyle);
        goto reconfig1;


    case WM_DROPFILES: {
        POINT pt;
        HDROP hDrop = (HDROP)wParam; int n,f;
        ev=edp;
        f=0;

        GetCursorPos(&pt);
        if (GetAsyncKeyState(VK_CONTROL)<0) f=1;
        if (GetAsyncKeyState(VK_SHIFT)<0)   f=2;
        if (f) ScreenToClient(hwnd,&pt);

        for (i=-1, k=0; i<k; i++)
        {
            n=DragQueryFile (hDrop, i, p=bstr, 255);
            if (i<0)
            {
                k=n;
            }
            else
            if (f==0)
            {
                LoadFile(p);
            }
            else
            if (f==2)
            {
                if (readstyle(p))
                {
                    CopyFile(p, defstyle, FALSE);
                }
                break;
            }
            else
            {
                if (i == 0 && -1 == getmoupos(pt.x ,pt.y))
                    break;

                ed_cmd(EK_SETVAR);
                ed_cmd(EK_INSERT, p);
                ed_cmd(KEY_RET);
            }
        }
        DragFinish(hDrop);
        SetForegroundWindow(hwnd);
        if (f==0) goto showf;
        if (f==2) goto reconfig1;
        goto p0;
        }

    case WM_QUERYENDSESSION:
        return (1 == QueryDiscard(hwnd,1));

    case WM_ENDSESSION:
    {
        //void savecfg(void); savecfg();
        return 0;
    }

    case WM_DESTROY:
        exit_edit();
        DragAcceptFiles(hwnd,FALSE);
        bb_unregister(hwnd);
        PostQuitMessage(0);
        return 0 ;


    case WM_ACTIVATE:
        i=LOWORD(wParam);
        if (i==WA_ACTIVE)
            clickflag=0;

        return 0;

    case WM_ACTIVATEAPP:
        if (wParam) {
            clickflag=2;
        }
        return 0;

    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
        if (alt_f) alt_f=2;

    case WM_MOUSEMOVE:
#if 0
    {
        static int wm;
        i = (short)HIWORD(lParam)/2;
        n = wm;
        wm = i;
        wParam = MAKELPARAM(0,(n-i)*30);
        goto mwhl;

    }
#endif
    case WM_LBUTTONDBLCLK:
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    case WM_MBUTTONUP:
    case WM_MBUTTONDOWN:

        if (drag==0 && domove (hwnd, message, wParam, lParam))
            return 0;

        do_mouse(hwnd, wParam, lParam, message);

        if (message==WM_MOUSEMOVE && 0==(wParam & (MK_LBUTTON | MK_RBUTTON)))
            return 0;

        goto p0;

    case WM_TIMER:

        if (wParam==2) {
            resetmsg(hwnd);
            goto p0;
        }

        if (wParam==4) {
            mousewheelaccu=0;
        t0:
            KillTimer(hwnd, wParam);
            return 0;
        }

        GetCursorPos(&pt);
        ScreenToClient(hwnd,&pt);
        o=getmoupos(pt.x ,pt.y);
        if (o!=tcmd) {
            settimer(hwnd, o, SCROLL_INTERVAL);
            return 0;
        }

        if (tcmd==0) goto t0;
        c=ltup; ltup=0;
        ed_cmd(tcmd);
        ed_cmd(tcmd);
        upd=1;
        ltup=c;
        k=GetAsyncKeyState(VK_SHIFT)&0x8000;
        domarking(k!=0 || (0==moumrk && 0==drag));
        goto p0;


    case WM_SIZE:
        if (SIZE_MINIMIZED == wParam)
            return 0;

        if (edp) upd=1;
        ed_cmd(EK_SIZE);
        new_back();

    case WM_MOVE:
        setsize(hwnd);
        goto p0;

/*
   case WM_WINDOWPOSCHANGED:
        ewx0 = ((LPWINDOWPOS) lParam)->x;
        ewy0 = ((LPWINDOWPOS) lParam)->y;
        ewxl = ((LPWINDOWPOS) lParam)->cx;
        ewyl = ((LPWINDOWPOS) lParam)->cy;
        cfg_f |= 1;
        break; //process wm_move/wm_size

    case WM_WINDOWPOSCHANGING:
        SnapWindowToEdge((WINDOWPOS*)lParam, 10, 0);
        setsize(hwnd);
        return 0;
*/

    case WM_VSCROLL:
        vscroll(wParam);
        goto p0;

    case WM_HSCROLL:
        hscroll(wParam);
        goto p0;

    case WM_SETFOCUS:
        k_alt = 0>GetAsyncKeyState(VK_MENU);
        k_shft= 0>GetAsyncKeyState(VK_SHIFT);
        k_ctrl= 0>GetAsyncKeyState(VK_CONTROL);
        CreateCaret(hwnd,NULL,My_CaretSize,zy);
        caret=1;
        checkftime(hwnd);
        goto f1;

    case WM_KILLFOCUS:
        DestroyCaret();
        caret=0;
    f1:
        if (edp) upd=1;
        goto p0;

p0:
        r=0;
p0r:
        set_update(hwnd);
        return r;


    case WM_ERASEBKGND:
        return 1;

    case WM_PAINT:
        paint_window (hwnd);
        return 0;


    case WM_COMMAND:
        switch (LOWORD(wParam)) {

        case CMD_HELP:
#if 0
            bbnote_help();
            return 0;
#else
            if (fileexist(set_my_path(bstr, "bbnote.txt")))
                LoadFile(bstr);
            else if (fileexist(set_my_path(bstr, "docs/bbnote.txt")))
                LoadFile(bstr);
            goto p0;
#endif


        case CMD_EXIT:
            goto quit;

        case CMD_MENU_2:
        filemenu:
            if (ed0)
            {
                struct edvars *e = ed0;
                struct strl   *s = NULL;
                while (e)
                {
                    char temp[MAX_PATH];
                    sprintf(temp, "&%s", fname(e->sfilename));
                    appendstr(&s, temp);
                    e = e->next;
                }
                bb_file_menu (hwnd, lParam, s);
            }
            return 0;

        case CMD_MENU_1:
            bb_menu(hwnd, lParam);
            return 0;

        case CMD_COLOR:
            goto reconfig;

        case CMD_UPD:
            settitle();
            if (edp) upd=1;
            goto p0;


        case CMD_ZOOM:
    zoom:
            ShowWindow(hwnd, IsZoomed(hwnd) ? SW_SHOWNORMAL : SW_MAXIMIZE);
            return 0;

        case CMD_SEARCH:
        search:
            if (edp) bb_search_dialog(hwnd);
            return 0;

        case CMD_CLOSE:
        closefile:
            if (edp)
            {
                if (1 != QueryDiscard_1(hwnd, 1)) goto p0;
                if (ed0->next==NULL)
                {
                    extern HWND mwnd;
                    SendMessage(mwnd, WM_KEYDOWN, VK_ESCAPE, 0);
                    //DestroyWindow(mwnd);
                }
                CloseFile();
            }
            goto p0;

        case CMD_OPEN:
        openfile:
            ev=edp;
            DoFileOpenSave(hwnd, 0);
showf:
            if (ev==NULL || ev->next)
            {
                edp = ev ? ev->next : ed0;
                settitle();
            }
            goto p0;

        case CMD_RELOAD:
        reload:
            if (edp) f_reload(1);
            goto p0;


        case CMD_LIST:
            lParam = 2;
            goto filemenu;

        case CMD_NEW:
        newfile:
            NewFile();
            goto p0;

        case CMD_SAVE:
        savefile:
            if (edp) DoFileOpenSave(hwnd, 2);
            goto p0;

        case CMD_SAVEAS:
            if (edp!=NULL) DoFileOpenSave(hwnd, 1);
            break;

        case CMD_SAVEALL:
        //saveall:
            return QueryDiscard(hwnd, 0);

        case CMD_UNDO:
            ed_cmd(KEY_C_Z);
            goto p0;

        case CMD_REDO:
            ed_cmd(KEY_CS_Z);
            goto p0;

        case CMD_ABOUT:
            oyncan_msgbox(
              VERSION_STRING
              "\n"
              "\nediting with style"
              "\n04/2003 by grischka"
              "\n"
              "\[email protected]"
              , NULL, 1);
              return 0;


        case CMD_OPTIONS:
            goto config;

        case CMD_INFO:
            resetmsg(hwnd);
            p=(char*)lParam;
            if (p[0]==1) p++;
            else infoflg=1,infotimer=SetTimer(hwnd,2,666,NULL);
            strcpy(infomsg,p);
            if (edp) upd=1;
            goto p0;


        case CMD_FILECHG:
        {
            struct edvars *p=edp;
            edp=(struct edvars*)lParam;
            settitle();
            set_update(hwnd);
            f_reload(0);
            edp=p;
            settitle();
            goto p0;
        }

        default:
            i = LOWORD(wParam);
            if (i>=CMD_FILE && i< CMD_FILE_M)
            {
                struct edvars *p=ed0;
                i-=CMD_FILE;
                for (;i && p!=NULL; p=p->next,i--);
                if (p) {
                    //edp = p; settitle();
                    insfile(p);
                    goto p0;
                }
                return 0;
            }
            break;

        }
        break;

quit:
    if (1 == QueryDiscard(hwnd, 1))
        DestroyWindow(hwnd);
    return 0;

    case WM_SYSKEYDOWN:
        f=3; goto k1;

    case WM_SYSKEYUP:
        f=2; goto k1;

    case WM_KEYUP:
        if (wParam==VK_CONTROL && drag==3)  setdragc(2);
        f=0; goto k1;

    case WM_KEYDOWN:
        if (wParam==VK_CONTROL && drag==2)  setdragc(3);
        if (wParam==VK_SCROLL) { scroll_lock^=1; goto p0; }

        f=1; k1:

        n=LOWORD(wParam);

#if 0
        sprintf(bstr,"key %d  stat %d",n,f);
        if (n!=VK_MENU) MessageBox(NULL, bstr, "", MB_OK|MB_TOPMOST|MB_SETFOREGROUND);
#endif
        n=trans_keys(n, f);
        //if (0==n) goto p0;
        if (0==n) return 0;

        if (n>=2110 && n<=2117) {
        vmark=k_alt!=0;
        domarking(1);
        ed_cmd(n-100);
        domarking(1);
        goto p0;
        }

        switch (n) {

        case KEY_F8: return 0;
        case KEY_A_RIGHT:
        case KEY_F6:   nextfile(); goto p0;
        case KEY_A_LEFT:
        case KEY_C_F6: prevfile(); goto p0;

        case KEY_F10:  goto zoom;
        case KEY_F3:
        case KEY_C_F:  goto search;
        case KEY_C_F4: goto closefile;
        case KEY_C_O:  goto openfile;
        //case KEY_A_F3: goto reload;
        case KEY_C_N:  goto newfile;
        case KEY_C_L:  lParam = 0; goto filemenu;

        case KEY_F4:
            QueryDiscard(hwnd, 0);
            bb_reconfig();
            return 0;

        case KEY_S_F4:
            if (IDOK == oyncan_msgbox("Do you want to write all files?", "", 1+8))
                QueryDiscard(hwnd, 4);
            return 0;


        case KEY_C_S:  goto savefile;
        case KEY_A_F4: goto quit;

        case KEY_A_F2:
config:
            n = tabs;
            bb_config_dialog(hwnd);
            if (n!=tabs) goto reload;
            return 0;

        case KEY_ESC:
            if (drag==0) goto quit;
            dragmove=0;
            do_mouse(hwnd, 0,0,WM_LBUTTONUP);
            goto p0;

        case KEY_UP:
        case KEY_DOWN:
            if (scroll_lock) n+=200;
            goto defkey;

        case KEY_LEFT:
        case KEY_RIGHT:
            if (scroll_lock) n=(n^1)+204;
            goto defkey;
        }

    defkey:
        domarking(0);
        ed_cmd(n);
        i=n;
        if (i!=KEY_C_A
         && i!=KEY_C_U
         && i!=KEY_C_7
         && i!=KEY_C_8
         && i!=KEY_C_9
         && i!=KEY_C_0
         && i!=KEY_TAB
         && i!=KEY_S_TAB
         )
            unmark();
        goto p0;


    case WM_MOUSEWHEEL:
        i = mousewheelaccu + mousewheelfac * (short)HIWORD(wParam);
        while (i < -300)
            ed_cmd(KEY_C_DOWN), i+=600;
        while (i >  300)
            ed_cmd(KEY_C_UP),   i-=600;

        mousewheelaccu=i;
        unmark();
        SetTimer(hwnd, 4, 200, NULL);
        goto p0;


    case WM_NCPAINT:
        return 0;


    case WM_CHAR:
        n = LOWORD(wParam);
        if (n<32||n==127) return 0;

        resetmsg(hwnd);
        ed_cmd(EK_CHAR, n);
        goto p0;



    case CMD_GOTOLINE:
        ed_cmd(EK_GOTOLINE,wParam-1);
        ed_cmd(EK_MARK,lpos,imin(lpos+1,nextline(lpos,1)));
        lmf=2;
        goto p0;

    case CMD_LOADFILE:
        r=LoadFile((char*)wParam);
        goto p0r;

    case CMD_NSEARCH:
        resetmsg(hwnd);
        if (wParam&8) {
            ed_cmd(EK_REPLACE,(char *)lParam);
            if (wParam&1)
               ed_cmd(EK_GOTO,fpos+strlen((char*)lParam));
            goto p0;
        }
        unmark();
        if (wParam!=0) {
            struct sea *s=(struct sea *)lParam;
            struct edvars *ev0;

            for (ev0=edp;;) {
                r=ed_search(s);
                if (r || 0==(s->sf&128)) break;
                s->sf &= ~4;
                if (s->sf & 1) {
                    if (edp->next==NULL) break;
                    nextfile();
                    s->from=0;
                    continue;
                }
                if (s->sf & 2) {
                    if (edp==ed0) break;
                    prevfile();
                    s->from=flen;
                    continue;
                }}
            if (r<=0) {
                edp=ev0;
                settitle();
            } else {
               ed_cmd(KEY_HOME);
               ed_cmd(EK_MARK,s->a,s->e);
               ed_cmd(EK_GOTO,s->a);
            }
        }
        goto p0r;

    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Пример #29
0
void HariMain(void)
{
  char s[40];
  struct MOUSE_DEC mdec;
  int mx, my;
  int i;
  unsigned int memtotal;
	unsigned int count;
	fifo8 timerfifo;

  char keybuf[KEYBUF_SIZE] = {0};
  char mousebuf[MOUSEBUF_SIZE] = {0};
	char timerbuf[8] = {0};
  struct BOOTINFO *binfo;
  struct MEMMAN *memman;

  shtctl_t *shtctl;
  sheet_t *sht_back, *sht_mouse, *sht_win;
  unsigned char *buf_back, buf_mouse[256], *buf_win;

  binfo = (struct BOOTINFO *) ADR_BOOTINFO;
  memman = (struct MEMMAN *)MEMMAN_ADDR;
	count = 0;

  init_gdtidt ();
  init_pic();
  io_sti();
  fifo8_init(&keyfifo, KEYBUF_SIZE, keybuf); /* keyboard */
  fifo8_init(&mousefifo, MOUSEBUF_SIZE, mousebuf); /* mouse */
	
	init_pit();

	fifo8_init(&timerfifo, 8, timerbuf);       /* timer */
	settimer(100, &timerfifo, 1);
	
  io_out8(PIC0_IMR, 0xf8); /* PIC1/keyboard/PIT设置为许可(11111000) */
  io_out8(PIC1_IMR, 0xef); /* 鼠标设置为许可(11101111) */

  init_keyboard ();
  enable_mouse(&mdec);
	memtotal = memtest(0x00400000, 0xbfffffff);
	memman_init(memman);
	memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */
	memman_free(memman, 0x00400000, memtotal - 0x00400000);

  init_palette();

  shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
  sht_back = sheet_alloc(shtctl);
  sht_mouse = sheet_alloc(shtctl);
	sht_win  = sheet_alloc(shtctl);
	
  buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);
	buf_win  = (unsigned char *) memman_alloc_4k(memman, 160 * 52);
	
  sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1);
  sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
	sheet_setbuf(sht_win, buf_win, 160, 52, -1);

  init_screen8(buf_back, binfo->scrnx, binfo->scrny);
  init_mouse_cursor8(buf_mouse, 99);
	make_window8(buf_win, 160, 52, "counter");
	
  sheet_slide(sht_back, 0, 0);

	/* make it in the middle. */
  mx = (binfo->scrnx - 16) / 2;
  my = (binfo->scrny - 28 - 16) / 2;
  //init_mouse_cursor8(mcursor, COL8_008484);
  sheet_slide(sht_mouse, mx, my);
	sheet_slide(sht_win, 80, 72);
	
  sheet_updown(sht_back, 0);
	sheet_updown(sht_win, 1);
  sheet_updown(sht_mouse, 2);

  //putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16);
  sprintf(s, "(%3d, %3d)", mx, my);
  putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s);
	sprintf(s, "memory %dMB   free : %dKB",
			    memtotal / (1024 * 1024), memman_total(memman) / 1024);
  putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s);
  sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48);

  for (;;) {
		++count;
		sprintf(s, "%u, %u", timerctl.count, timerctl.timeout);
		boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43);
		putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s);
		sheet_refresh(sht_win, 40, 28, 120, 44);
		
    io_cli();
    if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) == 0){
      io_sti();
    } else {
      if (fifo8_status(&keyfifo) != 0) {
        i = fifo8_get(&keyfifo);
        io_sti();
        sprintf(s, "%02X", i);
				boxfill8(buf_back, binfo->scrnx, COL8_008484,  0, 16, 15, 31);
				putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s);
        sheet_refresh(sht_back, 0, 16, 16, 32);
      } else if (fifo8_status(&mousefifo) != 0){
        i = fifo8_get(&mousefifo);
        io_sti();
        if (mouse_decode(&mdec, i) != 0) {
          sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);
          if ((mdec.btn & 0x01) != 0)
            s[1] = 'L';
          if ((mdec.btn & 0x02) != 0)
            s[3] = 'R';
          if ((mdec.btn & 0x04) != 0)
            s[2] = 'C';
          boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31);
          putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s);
          sheet_refresh(sht_back, 32, 16, 32 + 15 * 8, 32);

          /* 鼠标指针的移动 */
          //boxfill8(binfo->vram, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); /* 隐藏鼠标 */
          mx += mdec.x;
          my += mdec.y;
          if (mx < 0)
            mx = 0;
          if (my < 0)
            my = 0;
          if (mx > binfo->scrnx - 1)
            mx = binfo->scrnx - 1;
          if (my > binfo->scrny - 1)
            my = binfo->scrny - 1;

          sprintf(s, "(%3d, %3d)", mx, my);
          boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 79, 15); /* 隐藏坐标 */
          putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); /* 显示坐标 */
          sheet_refresh(sht_back, 0, 0, 80, 16);
          sheet_slide(sht_mouse, mx, my);
          //putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); /* 描画鼠标 */
        }
      } else if (fifo8_status(&timerfifo) != 0) {
				i = fifo8_get(&timerfifo);
				io_sti();
				putfonts8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, "10[sec]");
				sheet_refresh(sht_back, 0, 64, 56, 80);
			}
    }
  }
}
Пример #30
0
Файл: relay.c Проект: a2/Soxy
ssize_t forward_udp(rlyinfo *ri, UDP_ATTR *udp, int method)
{
  settimer(TIMEOUTSEC);
  if (method == DIRECT) {
    switch (ri->dir) {
    case UP:
      ri->top = 0;
      ri->len = SS_LEN;
      readn(ri);
      if (ri->nread > 0) {
	/* (check and) save down-ward sockaddr */
	memcpy(&udp->si.prc.addr, ri->ss, ri->len);
	udp->si.prc.len = ri->len;

	/* decode socks udp header and set it to up-side sockaddr */
	if (decode_socks_udp(udp, (u_char *)ri->buf) < 0)
	  return(-1);
	/* shift buf top pointer by udp header length */
	ri->top = udp->sv.len;
	/* open upward socket unless opened yet */
	/* XXXX little bit ambiguous ?? */
	if (udp->u < 0) {
	  if ((udp->u = socket(udp->si.prs.addr.sa.sa_family,
				     SOCK_DGRAM, IPPROTO_IP)) < 0)
	    return(-1);
	  ri->to = udp->u;
	}
	/* set destination(up-ward) sockaddr */
	memcpy(ri->ss, &udp->si.prs.addr, udp->si.prs.len);
	ri->len = udp->si.prs.len;

	/* set write data len */
	if (ri->nread - udp->sv.len < 0)
	  return(-1);
	ri->nw = ri->nread - udp->sv.len;
      }
      break;
    case DOWN:
      if (udp->sv.len <= 0)
	return(-1);
      /* shift buf top pointer by udp header length */
      ri->top = udp->sv.len;
      ri->len = SS_LEN;
      readn(ri);
      if(ri->nread > 0) {
	/* (check and) save up-ward sockaddr */
	memcpy(&udp->si.prs.addr, ri->ss, ri->len);
	udp->si.prs.len = ri->len;

	/* prepend socks udp header to buffer */
	memcpy(ri->buf, udp->sv.data, udp->sv.len);
	/* set destination(down-ward) sockaddr */
	memcpy(ri->ss, &udp->si.prc.addr, udp->si.prc.len);
	ri->len = udp->si.prc.len;

	/* reset buf top */
	ri->top = 0;
	/* set write data len */
	ri->nw = ri->nread + udp->sv.len;
      }
      break;
    }
    writen(ri);
  } else {
    /* PROXY just relay */
    /* XXXXX  not yet */
  }
  settimer(0);
  if (ri->nread == 0)
    /* none the EOF case of UDP */
    return(0);
  if (ri->nread < 0)
    return(-1);
  return(ri->nwritten);
}