Exemple #1
0
/*DISPATCHER_UIPCALL(smtp_appcall, state)*/
void
smtp_appcall(void *state)
{
  if(uip_connected()) {
    /*    senddata();*/
    return;
  }
  if(uip_acked()) {
    acked();
  }
  if(uip_newdata()) {
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {    
    senddata();
  }
  /*  if(uip_closed()) {
    printf("Dnoe\n");
    }*/


}
Exemple #2
0
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void *ts)
{
  if(uip_connected()) {
    tcp_markconn(uip_conn, &s);
    buf_init(&buf);
    s.bufptr = 0;
    s.state = STATE_NORMAL;
    shell_start();
  }

  if(s.state == STATE_CLOSE) {
    s.state = STATE_NORMAL;
    uip_close();
    return;
  }
  if(uip_closed() ||
     uip_aborted() ||
     uip_timedout()) {
    closed();
  }
  if(uip_acked()) {
    acked();
  }
  if(uip_newdata()) {
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked() ||
     uip_connected() ||
     uip_poll()) {
    senddata();
  }
}
Exemple #3
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }

  if(uip_aborted()) {
    webclient_aborted();
  }
  if(uip_timedout()) {
    webclient_timedout();
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void *ts)
{
  if(uip_connected()) {
    if(!connected) {
      buf_init(&buf);
      s.bufptr = 0;
      s.state = STATE_NORMAL;
      connected = 1;
      shell_start();
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      ts = (char *)0;
    } else {
      uip_send(telnetd_reject_text, strlen(telnetd_reject_text));
      ts = (char *)1;
    }
    tcp_markconn(uip_conn, ts);
  }

  if(!ts) {
    if(s.state == STATE_CLOSE) {
      s.state = STATE_NORMAL;
      uip_close();
      return;
    }
    if(uip_closed() ||
       uip_aborted() ||
       uip_timedout()) {
      shell_stop();
      connected = 0;
    }
    if(uip_acked()) {
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      acked();
    }
    if(uip_newdata()) {
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      newdata();
    }
    if(uip_rexmit() ||
       uip_newdata() ||
       uip_acked() ||
       uip_connected() ||
       uip_poll()) {
      senddata();
      if(s.numsent > 0) {
	timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      }
    }
    if(uip_poll()) {
      if(timer_expired(&s.silence_timer)) {
        uip_close();
        tcp_markconn(uip_conn, NULL);
      }
    }
  }
}
/******************************************************************************
* void exosite_appcall(void)
*
* This function is uIP's application function.  It is called whenever a uIP 
* event occurs (e.g. when a new connection is established, new data arrives, 
* sent data is acknowledged, data needs to be retransmitted, etc.).
* 
******************************************************************************/ 
void exosite_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    senddata();
    return;
  }

  if(s.state == EXO_STATE_CLOSE) {
    uip_abort();
    return;
  }
  
  if(uip_aborted()) {
  }
  if(uip_timedout()) {
  }

  if(uip_acked()) {
    s.timer = 0;
    acked();
  }

  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
 
  if(uip_rexmit() || uip_newdata() || uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == EXO_TIMEOUT) {
      uip_abort();
      return;
    }
  }
#if 0  
  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      memset(s.rxdata,0,sizeof(s.rxdata));
    } else {
      if(resolv_lookup(s.host) == NULL) {
	      resolv_query(s.host);
      }
    }
  }
#endif

}
Exemple #6
0
/*-----------------------------------------------------------------------------------*/
void
telnet_app(void *ts)
{
  struct telnet_state *s = (struct telnet_state *)ts;
    
  if(uip_connected()) {
    s->flags = 0;
    telnet_connected(s);
    senddata(s);
    return;
  }
  
  if(uip_closed()) {
    telnet_closed(s);
  }
  
  if(uip_aborted()) {
    telnet_aborted(s);
  }
  if(uip_timedout()) {
    telnet_timedout(s);
  }

  if(s->flags & FLAG_CLOSE) {
    uip_close();
    return;
  }
  if(s->flags & FLAG_ABORT) {
    uip_abort();
    return;
  }
  if(uip_acked()) {
    acked(s);
  }
  if(uip_newdata()) {
    telnet_newdata(s, (char *)uip_appdata, uip_datalen());
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata(s);
  } else if(uip_poll()) {
    senddata(s);
  }
}
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void)
{
  static unsigned int i;
  if(uip_connected()) {
    /*    tcp_markconn(uip_conn, &s);*/
    for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) {
      s.lines[i] = NULL;
    }
    s.bufptr = 0;
    s.state = STATE_NORMAL;

    shell_start();
  }

  if(s.state == STATE_CLOSE) {
    s.state = STATE_NORMAL;
    uip_close();
    return;
  }
  
  if(uip_closed() ||
     uip_aborted() ||
     uip_timedout()) {
    closed();
  }
  
  if(uip_acked()) {
    acked();
  }
  
  if(uip_newdata()) {
    newdata();
  }
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked() ||
     uip_connected() ||
     uip_poll()) {
    senddata();
  }
}
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void *state)
{
  char *dataptr;
  
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    tcp_markconn(uip_conn, &s);
    return;
  }

  if(uip_timedout()) {
    webclient_timedout();
  }

  if(uip_aborted()) {
    webclient_aborted();
  }

  if(state == NULL) {
    uip_abort();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }


  /* The acked() and newdata() functions may alter the uip_appdata
     ptr, so we need to store it in the "dataptr" variable so that we
     can restore it before the senddata() function is called. */  
  dataptr = uip_appdata;
  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }

  uip_appdata = dataptr;
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      /*      conn = uip_connect(uip_conn->ripaddr, s.port);
      if(conn != NULL) {
	dispatcher_markconn(conn, NULL);
	init_connection();
	}*/
#if UIP_UDP
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
#endif /* UIP_UDP */
      webclient_get(s.host, s.port, s.file);
    }
  }
}
/*-----------------------------------------------------------------------------------*/
void
websocket_http_client_appcall(void *state)
{
  char *dataptr;
  struct websocket_http_client_state *s = state;
  
  if(uip_connected()) {
    s->timer = 0;
    s->outputbufptr = 0;
    s->outputbuf_sendnext = 0;
    s->state = WEBSOCKET_HTTP_CLIENT_STATE_STATUSLINE;
    senddata(s);
    return;
  }

  if(uip_timedout()) {
    websocket_http_client_timedout(s);
  }

  if(uip_aborted()) {
    /*    printf("aborted\n"); */
    websocket_http_client_aborted(s);
  }

  if(state == NULL) {
    uip_abort();
    return;
  }

  if(s->state == WEBSOCKET_HTTP_CLIENT_STATE_CLOSE) {
    websocket_http_client_closed(s);
    uip_abort();
    return;
  }


  /* The acked() and newdata() functions may alter the uip_appdata
     ptr, so we need to store it in the "dataptr" variable so that we
     can restore it before the senddata() function is called. */  
  dataptr = uip_appdata;
  
  if(uip_acked()) {
    s->timer = 0;
    acked(s);
  }
  if(uip_newdata()) {
    s->timer = 0;
    newdata(s);
  }

  uip_appdata = dataptr;
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata(s);
  } else if(uip_poll()) {
    senddata(s);
    ++s->timer;
    if(s->timer == WEBSOCKET_HTTP_CLIENT_TIMEOUT) {
      websocket_http_client_timedout(s);
      uip_abort();
      return;
    }
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    if(s->httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      websocket_http_client_datahandler(s, NULL, 0);
    } else {
#if UIP_UDP
      if(mdns_lookup(s->host) == NULL) {
	mdns_query(s->host);
      }
#endif /* UIP_UDP */
      websocket_http_client_get(s, s->host, s->port, s->file,
                                s->subprotocol);
    }
  }
}
Exemple #10
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
	//printf("%s() masuk\r\n", __FUNCTION__);
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    //webclient_connected();
    //printf("%s(): Connected\r\n", __FUNCTION__);
	return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    //webclient_closed();
    //printf("%s(): Closed\r\n", __FUNCTION__);
	uip_abort();
    return;
  }

  if(uip_aborted()) {	 
    //webclient_aborted();
	//printf("%s(): Aborted\r\n", __FUNCTION__);
  }
  if(uip_timedout()) {
    //webclient_timedout();
	 //printf("%s(): Timeout 1\r\n", __FUNCTION__);
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
	  //printf("%s() masuk .... ke f newdata\r\n", __FUNCTION__);
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      //webclient_timedout();
	 // printf("%s(): Timeout 2\r\n", __FUNCTION__);
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
	  /*
	  if(resolv_lookup(s.host) == NULL) {
		resolv_query(s.host);
      }*/
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Exemple #11
0
/*---------------------------------------------------------------------------*/
static void
appcall(void *state)
{
  struct tcp_socket *s = state;

  if(s != NULL && s->c != NULL && s->c != uip_conn) {
    /* Safe-guard: this should not happen, as the incoming event relates to
     * a previous connection */
    return;
  }
  if(uip_connected()) {
    /* Check if this connection originated in a local listen
       socket. We do this by checking the state pointer - if NULL,
       this is an incoming listen connection. If so, we need to
       connect the socket to the uip_conn and call the event
       function. */
    if(s == NULL) {
      for(s = list_head(socketlist);
	  s != NULL;
	  s = list_item_next(s)) {
	if((s->flags & TCP_SOCKET_FLAGS_LISTENING) != 0 &&
	   s->listen_port != 0 &&
	   s->listen_port == uip_htons(uip_conn->lport)) {
	  s->flags &= ~TCP_SOCKET_FLAGS_LISTENING;
          s->output_data_max_seg = uip_mss();
	  tcp_markconn(uip_conn, s);
	  call_event(s, TCP_SOCKET_CONNECTED);
	  break;
	}
      }
    } else {
      s->output_data_max_seg = uip_mss();
      call_event(s, TCP_SOCKET_CONNECTED);
    }

    if(s == NULL) {
      uip_abort();
    } else {
      if(uip_newdata()) {
        newdata(s);
      }
      senddata(s);
    }
    return;
  }

  if(uip_timedout()) {
    call_event(s, TCP_SOCKET_TIMEDOUT);
    relisten(s);
  }

  if(uip_aborted()) {
    tcp_markconn(uip_conn, NULL);
    call_event(s, TCP_SOCKET_ABORTED);
    relisten(s);

  }

  if(s == NULL) {
    uip_abort();
    return;
  }

  if(uip_acked()) {
    acked(s);
  }
  if(uip_newdata()) {
    newdata(s);
  }

  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata(s);
  } else if(uip_poll()) {
    senddata(s);
  }

  if(s->output_data_len == 0 && s->flags & TCP_SOCKET_FLAGS_CLOSING) {
    s->flags &= ~TCP_SOCKET_FLAGS_CLOSING;
    uip_close();
    s->c = NULL;
    tcp_markconn(uip_conn, NULL);
    s->c = NULL;
    /*call_event(s, TCP_SOCKET_CLOSED);*/
    relisten(s);
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    s->c = NULL;
    call_event(s, TCP_SOCKET_CLOSED);
    relisten(s);
  }
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
static void
appcall(void *state)
{
  struct tcp_socket *s = state;

  if(uip_connected()) {
    /* Check if this connection originated in a local listen
       socket. We do this by checking the state pointer - if NULL,
       this is an incoming listen connection. If so, we need to
       connect the socket to the uip_conn and call the event
       function. */
    if(s == NULL) {
      for(s = list_head(socketlist);
	  s != NULL;
	  s = list_item_next(s)) {
	if(s->is_listening != 0 &&
	   s->listen_port != 0 &&
	   s->listen_port == uip_htons(uip_conn->lport)) {
	  s->is_listening = 0;
	  tcp_markconn(uip_conn, s);
	  call_event(s, TCP_SOCKET_CONNECTED);
	  break;
	}
      }
    } else {
      call_event(s, TCP_SOCKET_CONNECTED);
    }

    if(s == NULL) {
      uip_abort();
    } else {
      senddata(s);
    }
    return;
  }

  if(uip_timedout()) {
    call_event(s, TCP_SOCKET_TIMEDOUT);
    relisten(s);
  }

  if(uip_aborted()) {
    call_event(s, TCP_SOCKET_ABORTED);
    relisten(s);
  }

  if(s == NULL) {
    uip_abort();
    return;
  }
  
  if(uip_acked()) {
    acked(s);
  }
  if(uip_newdata()) {
    newdata(s);
  }

  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata(s);
  } else if(uip_poll()) {
    senddata(s);
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    call_event(s, TCP_SOCKET_CLOSED);
    relisten(s);
  }
}