示例#1
0
// Receive a HTTP request
void httpd_recv(chanend tcp_svr, xtcp_connection_t *conn)
{
  struct httpd_state_t *hs = (struct httpd_state_t *) conn->appstate;
  char data[XTCP_CLIENT_BUF_SIZE];
  int len;

  // Receive the data from the TCP stack
  len = xtcp_recv(tcp_svr, data);

  // If we already have data to send, return
  if ( hs == NULL || hs->dptr != NULL)
    {
      return;
    }

  // Otherwise we have data, so parse it
  parse_http_request(hs, &data[0], len);

  // If we are required to send data
  if (hs->dptr != NULL)
    {
      // Initate a send request with the TCP stack.
      // It will then reply with event XTCP_REQUEST_DATA
      // when it's ready to send
      xtcp_init_send(tcp_svr, conn);
    }
  ////
}
示例#2
0
// Receive a HTTP request
void telnetd_recv(chanend tcp_svr, xtcp_connection_t *conn)
{
	struct telnetd_state_t *hs = (struct telnetd_state_t *) conn->appstate;
	char data[XTCP_CLIENT_BUF_SIZE];
	int len;

	// Receive the data from the TCP stack
	len = xtcp_recv(tcp_svr, data);

	// Otherwise we have data, so parse it
        parse_telnet_stream(tcp_svr, conn, hs, &data[0], len);
}
示例#3
0
// xscope socket data handler
void xtcp_handle_xscope_tcp_event(chanend c_xtcp, xtcp_connection_t *conn)
{
  // Ignore events that are not directly relevant to tcp handler
  //printintln(conn->event);
  switch (conn->event) {
    case XTCP_IFUP:
    case XTCP_IFDOWN:
      conn_active = 0;
      return;
    case XTCP_ALREADY_HANDLED:
      return;
    default:
      break;
  }

  // Check if the connection is an client app connection
  if (conn->local_port == TCP_XSCOPE_PORT) {
    switch (conn->event) {
      case XTCP_NEW_CONNECTION:
        if (conn_active) {
          printstrln("a host connection is already active");
          xtcp_abort(c_xtcp, conn);
    	}
    	else
          conn_active = 1;
        break;
      case XTCP_RECV_DATA: {
          xtcp_recv(c_xtcp, (char *) &xscope_data);
          process_xscope_data(c_xtcp, xscope_data);
        }
        break;
      case XTCP_SENT_DATA:
      case XTCP_REQUEST_DATA:
      case XTCP_RESEND_DATA:
        tcp_send(c_xtcp, conn);
        break;
      case XTCP_TIMED_OUT:
      case XTCP_ABORTED:
      case XTCP_CLOSED:
        conn_active = 0;
        break;
      default:
        // Ignore anything else
        break;
      }
    conn->event = XTCP_ALREADY_HANDLED;
  }
  return;
}
示例#4
0
void httpd_recv(chanend tcp_svr,
                xtcp_connection_t *conn,
                chanend page_svr,
                chanend led_svr)
{
  struct httpd_state_t *hs = (struct httpd_state_t *) conn->appstate;
  char data[XTCP_CLIENT_BUF_SIZE];
  int len; 

  len = xtcp_recv(tcp_svr, data);
  // this assumes that a request fits in one read!!
  if (hs == NULL || hs->pss.cmdptr != 0) 
    return;

  parse_http_request(hs, &data[0], len, page_svr, led_svr);
  if (hs->pss.cmdptr != 0)
    xtcp_init_send(tcp_svr, conn);
  else
    xtcp_close(tcp_svr, conn);
}
void telnet_config_event_handler(chanend c_xtcp,
                                 chanend c_uart_config,
                                 chanend c_flash_data,
                                 xtcp_connection_t *conn)
{

  switch (conn->event)
    {
    case XTCP_IFUP:
    case XTCP_IFDOWN:
    case XTCP_ALREADY_HANDLED:
      return;
    default:
      break;
    }


  if (conn->local_port == S2E_TELNET_CONFIG_PORT) {
    connection_state_t *st = get_state_from_connection(conn);
    int close_request;
    int len;
    switch (conn->event)
      {
      case XTCP_NEW_CONNECTION:
        st = get_new_state();
        if (!st) {
          xtcp_abort(c_xtcp, conn);
          break;
        }
        st->sending_welcome = 1;
        st->sending_ack = 0;
        st->err = NULL;
        st->conn_id = conn->id;
        init_telnet_parse_state(&st->telnet_parsing_state);
        reset_parsing_state(st);
        xtcp_init_send(c_xtcp, conn);
        break;
      case XTCP_RECV_DATA:
        len = xtcp_recv(c_xtcp, buf);
        if (!st || !st->active)
          break;

        len = parse_telnet_buffer(buf,
                                  len,
                                  &st->telnet_parsing_state,
                                  &close_request);
        parse_config(c_xtcp, c_uart_config, c_flash_data, conn, buf, len, st);
        if (close_request)
          xtcp_close(c_xtcp, conn);
        break;
      case XTCP_REQUEST_DATA:
      case XTCP_RESEND_DATA:
        if (!st || !st->active) {
          xtcp_complete_send(c_xtcp);
          break;
        }

        // When sending either st->sending_welcome is true,
        // st->sending_ack is true or st->err is non null. Depending on
        // whether the connection is sending a welcome message, ack or
        // error message

        if (st->sending_welcome) {
          xtcp_send(c_xtcp, welcome_msg, sizeof(welcome_msg));
        }
        else if (st->sending_ack) {
          int len = construct_ack(st, buf);
          xtcp_send(c_xtcp, buf, len);
        }
        else if (st->err) {
          int len = strlen(st->err);
          strcpy(buf, st->err);
          buf[len] = '\n';
          xtcp_send(c_xtcp, buf, len+1);
        }
        else {
          xtcp_complete_send(c_xtcp);
        }
        break;
      case XTCP_SENT_DATA:
        xtcp_complete_send(c_xtcp);
        if (st) {
          st->sending_ack = 0;
          st->sending_welcome = 0;
          st->err = NULL;
        }
        break;
      case XTCP_CLOSED:
      case XTCP_ABORTED:
      case XTCP_TIMED_OUT:
        if (st) {
          st->active = 0;
        }
        break;
      default:
        break;
    }
    conn->event = XTCP_ALREADY_HANDLED;
  }

}