Beispiel #1
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
ctk_vncserver_appcall(void *state)
{
  static struct vnc_server_state *vs;

  vs = (struct vnc_server_state *)(state);

  if(uip_connected()) {

    /* Since we've just been connected, the state pointer should be
       NULL and we need to allocate a new state object. If we have run
       out of memory for state objects, we'll have to abort the
       connection and return. */
    if(vs == NULL) {
      vs = alloc_state();
      if(vs == NULL) {
	uip_close();
	return;
      }
      tcp_markconn(uip_conn, (void *)vs);
    }
  } else if(uip_closed() || uip_aborted()) {
    if(vs != NULL) {
      dealloc_state(vs);
    }
    return;
  }
  vnc_server_appcall(vs);
}
Beispiel #3
0
void
ems_net_main(void)
{
  if (uip_connected()) {
    if (ems_conn == NULL) {
      ems_conn = uip_conn;
      uip_conn->wnd = EMS_BUFFER_LEN - 1;
    } else {
      /* if we have already an connection, send an error */
      uip_send("ERROR: Connection blocked\n", 27);
    }
  } else if (uip_acked()) {
    /* If the peer is not our connection, close it */
    if (ems_conn != uip_conn) {
      uip_close();
    } else {
      /* Some data we have sent was acked, jipphie */
      ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
        ems_recv_buffer.len -= ems_recv_buffer.sent;
        memmove(ems_recv_buffer.data,
                ems_recv_buffer.data + ems_recv_buffer.sent,
                ems_recv_buffer.len);
      }
    }
  } else if (uip_closed() || uip_aborted() || uip_timedout()) {
Beispiel #4
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);

  petsciiconv_topetscii(s->filename, sizeof(s->filename));
  s->fd = cfs_open(s->filename, CFS_READ);
  petsciiconv_toascii(s->filename, sizeof(s->filename));
  if(s->fd < 0) {
    strcpy(s->filename, "notfound.html");
    s->fd = cfs_open(s->filename, CFS_READ);
    petsciiconv_toascii(s->filename, sizeof(s->filename));
    if(s->fd < 0) {
      PT_WAIT_THREAD(&s->outputpt,
                     send_headers(s, http_header_404));
      PT_WAIT_THREAD(&s->outputpt,
                     send_string(s, "not found"));
      uip_close();
      webserver_log_file(&uip_conn->ripaddr, "404 (no notfound.html)");
      PT_EXIT(&s->outputpt);
    }
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s, http_header_404));
    webserver_log_file(&uip_conn->ripaddr, "404 - notfound.html");
  } else {
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s, http_header_200));
  }
  PT_WAIT_THREAD(&s->outputpt, send_file(s));
  cfs_close(s->fd);
  s->fd = -1;
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
Beispiel #5
0
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);

  s->script = NULL;
  s->script = httpd_simple_get_script(&s->filename[1]);
  if(s->script == NULL) {
    strncpy(s->filename, "/notfound.html", sizeof(s->filename));
    PT_WAIT_THREAD(&s->outputpt,
                   send_headers(s, http_header_404));
    PT_WAIT_THREAD(&s->outputpt,
                   send_string(s, NOT_FOUND));
    uip_close();
    webserver_log_file(&uip_conn->ripaddr, "404 - not found");
    PT_EXIT(&s->outputpt);
  } else {
    PT_WAIT_THREAD(&s->outputpt,
                   send_headers(s, http_header_200));
    PT_WAIT_THREAD(&s->outputpt, s->script(s));
  }
  s->script = NULL;
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
Beispiel #6
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();
  }
}
Beispiel #7
0
/*-----------------------------------------------------------------------------------*/
static void
acked(void)    
{  
  s.sendptr += s.sentlen;
  s.sentlen = 0;

  if(s.sendptr == s.textlen) {
    switch(s.state) {
    case STATE_SEND_DATA_HEADERS:
      s.state = STATE_SEND_DATA_MESSAGE;
      s.sendptr = s.textlen = 0;
      break;
    case STATE_SEND_DATA_MESSAGE:
      s.state = STATE_SEND_DATA_END;
      s.sendptr = s.textlen = 0;
      break;
    case STATE_SEND_DATA_END:
      s.state = STATE_SEND_QUIT;
      s.sendptr = s.textlen = 0;
      break;
    case STATE_SEND_QUIT:
      s.state = STATE_SEND_DONE;
      smtp_done(SMTP_ERR_OK);
      uip_close();
      break;
    }
  }
}
static void contiki_appcall(void *data)
{
	contiki_data_t *s = (contiki_data_t *)data;

	if (uip_closed() || uip_aborted() || uip_timedout()) {
		//xprintf("closed or aborted or timedout\n");
		if (s->state == READING || s->state == WRITTING) {
			s->state = ERROR;
		} else {
			s->state = CLOSED;
		}
		process_post_synch(s->process, xively_event, s);
	} else if (uip_connected()) {
		s->state = CONNECTED;
		PSOCK_INIT(&s->p, NULL, 0);
		process_post_synch(s->process, xively_event, s);
	} else if (uip_newdata()) {
		if (s->state == READING) {
			s->state = READ_END;
			process_post_synch(s->process, xively_event, s);
		}
	}
	if (s->state == CLOSING) {
		uip_close();
	}
	handle_output(s);
}
void uip_task_appcall()
{  
	if(uip_connected()) 
	{
		socket_process_new_connect_();
	}else
	if(uip_poll())
	{
		if(uip_stopped(uip_conn))
		{
			socket_process_try_restart_();
		}
		
		socket_process_write_();
	}else
	if(uip_newdata())
	{
		socket_process_new_data_();
		socket_process_write_();
	}else
	if(uip_aborted() || uip_closed())
	{
		socket_process_close_();
	}else
	if(uip_timedout())
	{
		socket_process_timeout_();
		uip_close();
	}else
	if(uip_acked() || uip_rexmit())
	{
		socket_process_write_();
	}
}
Beispiel #10
0
static void
irc_main(void)
{
    if (uip_aborted() || uip_timedout()) {
	IRCDEBUG ("connection aborted\n");
	irc_conn = NULL;
    }

    if (uip_closed()) {
	IRCDEBUG ("connection closed\n");
	irc_conn = NULL;
    }

    if (uip_connected()) {
	IRCDEBUG ("new connection\n");
	STATE->stage = IRC_SEND_USERNICK;
	STATE->sent = IRC_SEND_INIT;
#ifdef ECMD_IRC_SUPPORT
	STATE->reparse = 0;
#endif
	*STATE->outbuf = 0;
    }

    if (STATE->stage == IRC_SEND_JOIN
	&& uip_acked ())
	STATE->stage ++;

    else if (STATE->stage == IRC_CONNECTED
	     && uip_acked ()) {
	*STATE->outbuf = 0;

#ifdef ECMD_IRC_SUPPORT
	if (STATE->reparse)
	    irc_handle_ecmd ();
#endif
    }

    else if (uip_newdata() && uip_len) {
	((char *) uip_appdata)[uip_len] = 0;
	IRCDEBUG ("received data: %s\n", uip_appdata);

	if (irc_parse ()) {
	    uip_close ();	/* Parse error */
	    return;
	}
    }

    if (uip_rexmit ())
	irc_send_data (STATE->sent);

    else if ((STATE->stage > STATE->sent || STATE->stage == IRC_CONNECTED)
	     && (uip_newdata()
		 || uip_acked()
		 || uip_connected()))
	irc_send_data (STATE->stage);

    else if (STATE->stage == IRC_CONNECTED && uip_poll() && *STATE->outbuf)
	irc_send_data (STATE->stage);
}
Beispiel #11
0
int16_t parse_cmd_wdreset(char *cmd, char *output, uint16_t len)
{
    status.request_wdreset = 1;
#ifdef UIP_SUPPORT
    uip_close();
#endif
    return ECMD_FINAL_OK;
}
Beispiel #12
0
void yport_net_main(void)
{
  if(uip_connected()) {
    if (yport_conn == NULL) {
      yport_conn = uip_conn;
      uip_conn->wnd = YPORT_BUFFER_LEN - 1;
    }
    else 
      /* if we have already an connection, send an error */
      uip_send("ERROR: Connection blocked\n", 27);
  } else if (uip_acked()) {
    /* If the peer is not our connection, close it */
    if (yport_conn != uip_conn) 
      uip_close();
    else {
      /* Some data we have sent was acked, jipphie */
      /* disable interrupts */
      uint8_t sreg = SREG; cli();
      yport_recv_buffer.len -= yport_recv_buffer.sent;
      /* We should use memmove, because the data may overlap */
      memmove(yport_recv_buffer.data, 
              yport_recv_buffer.data + yport_recv_buffer.sent,
              yport_recv_buffer.len);
      /* enable interrupts again */
      SREG = sreg;
    }
  } else if (uip_closed() || uip_aborted() || uip_timedout()) {
    /* if the closed connection was our connection, clean yport_conn */
    if (yport_conn == uip_conn)
      yport_conn = NULL;
  } else if (uip_newdata()) {
    if (uip_len <= YPORT_BUFFER_LEN && yport_rxstart(uip_appdata, uip_len) != 0) {
      /* Prevent the other side from sending more data */
      uip_stop();
    }
  } 
  if (uip_poll() 
      && uip_conn == yport_conn 
      && uip_stopped(yport_conn)
      && yport_send_buffer.sent == yport_send_buffer.len)
    uip_restart();
  /* Send data */
  if ((uip_poll() 
       || uip_acked()
       || uip_rexmit())
      && yport_conn == uip_conn 
      && yport_recv_buffer.len > 0) {
    /* We have recieved data, lets propagade it */
    /* disable interrupts */
    uint8_t sreg = SREG; cli();
    /* Send the data */
    uip_send(yport_recv_buffer.data, yport_recv_buffer.len);
    /* so many data was send */
    yport_recv_buffer.sent = yport_recv_buffer.len;
    /* enable interrupts again */
    SREG = sreg;
  }
}
Beispiel #13
0
/*---------------------------------------------------------------------*/
static
PT_THREAD(recv_tcpthread(struct pt *pt))
{
  PT_BEGIN(pt);

  /* Read the header. */
  PT_WAIT_UNTIL(pt, uip_newdata() && uip_datalen() > 0);

  if(uip_datalen() < sizeof(struct codeprop_tcphdr)) {
    PRINTF(("codeprop: header not found in first tcp segment\n"));
    uip_abort();
    goto thread_done;
  }

  s.len = uip_htons(((struct codeprop_tcphdr *)uip_appdata)->len);
  s.addr = 0;
  uip_appdata += sizeof(struct codeprop_tcphdr);
  uip_len -= sizeof(struct codeprop_tcphdr);

  xmem_erase(XMEM_ERASE_UNIT_SIZE, EEPROMFS_ADDR_CODEPROP);

  /* Read the rest of the data. */
  do {      
    if(uip_len > 0) {
      xmem_pwrite(uip_appdata, uip_len, EEPROMFS_ADDR_CODEPROP + s.addr);
      s.addr += uip_len;
    }
    if(s.addr < s.len) {
      PT_YIELD_UNTIL(pt, uip_newdata());
    }	
  } while(s.addr < s.len);

  /* Kill old program. */
  elfloader_unload();

  /* Link, load, and start new program. */
  int s;
  static char msg[30 + 10];
  s = elfloader_load(EEPROMFS_ADDR_CODEPROP);
  if (s == ELFLOADER_OK)
    sprintf(msg, "ok\n");
  else
    sprintf(msg, "err %d %s\n", s, elfloader_unknown);
    
  /* Return "ok" message. */
  do {
    s = strlen(msg);
    uip_send(msg, s);
    PT_WAIT_UNTIL(pt, uip_acked() || uip_rexmit() || uip_closed());
  } while(uip_rexmit());

  /* Close the connection. */
  uip_close();
    
 thread_done:;
  PT_END(pt);
}
Beispiel #14
0
/* -----------------------------------------------------------------------------
 *
 * -------------------------------------------------------------------------- */
static void uip_xtcpd_handle_poll(xtcpd_state_t *s)
{
 if (s->s.ack_request) {
   uip_flags |= UIP_NEWDATA;
   uip_slen = 0;
   s->s.ack_request = 0;
 }

  if (s->s.abort_request) {
    /* ----------------------------------- */
    if (uip_udpconnection()) {
      uip_udp_conn->lport = 0;
      xtcpd_event(XTCP_CLOSED, s);
    } else {
      uip_abort();
    }
    s->s.abort_request = 0;
  } else if (s->s.close_request) {
    /* ----------------------------------- */
    if (uip_udpconnection()) {
      uip_udp_conn->lport = 0;
      xtcpd_event(XTCP_CLOSED, s);
    }
    else
      uip_close();
    s->s.close_request = 0;
  } else if (s->s.connect_request) {
      /* ----------------------------------- */
      if (uip_udpconnection()) {
      init_xtcpd_state(s,
                       XTCP_PROTOCOL_UDP,
                       *((xtcp_ipaddr_t *) (&uip_udp_conn->ripaddr)),
                       uip_udp_conn->lport,
                       uip_udp_conn->rport,
                       uip_udp_conn);
      xtcpd_event(XTCP_NEW_CONNECTION, s);
      s->s.connect_request = 0;
    }
  } else if (s->s.send_request) {
     /* ----------------------------------- */
    int len;
    if (s->linknum != -1) {
      len = do_xtcpd_send(xtcp_cons.links[s->linknum],
                       XTCP_REQUEST_DATA,
                       s,
                       uip_appdata,
                       uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
      uip_send(uip_appdata, len);
    }
    s->s.send_request--;
  } else if (s->s.poll_interval != 0 &&
           timer_expired(&(s->s.tmr))){
    /* ----------------------------------- */
    xtcpd_event(XTCP_POLL, s);
    timer_set(&(s->s.tmr), s->s.poll_interval);
  }
}
Beispiel #15
0
static void
jabber_main(void)
{
  if (uip_aborted() || uip_timedout())
  {
    JABDEBUG("connection aborted\n");
    jabber_conn = NULL;
  }

  if (uip_closed())
  {
    JABDEBUG("connection closed\n");
    jabber_conn = NULL;
  }

  if (uip_connected())
  {
    JABDEBUG("new connection\n");
    STATE->stage = JABBER_OPEN_STREAM;
    STATE->sent = JABBER_INIT;

#ifdef JABBER_STARTUP_MESSAGE_SUPPORT
    strncpy_P(STATE->target, PSTR(CONF_JABBER_BUDDY), sizeof(STATE->target));
    strncpy_P(STATE->outbuf, jabber_startup_text, sizeof(STATE->outbuf));
    STATE->action = JABBER_ACTION_MESSAGE;
#endif /* JABBER_STARTUP_MESSAGE_SUPPORT */
  }

  if (uip_acked() && STATE->stage == JABBER_CONNECTED)
  {
    STATE->action = JABBER_ACTION_NONE;
    *STATE->outbuf = 0;
  }

  if (uip_newdata() && uip_len)
  {
    /* Zero-terminate */
    ((char *) uip_appdata)[uip_len] = 0;
    JABDEBUG("received data: %s\n", uip_appdata);

    if (jabber_parse())
    {
      uip_close();              /* Parse error */
      return;
    }
  }

  if (uip_rexmit())
    jabber_send_data(STATE->stage, STATE->action);

  else if ((STATE->stage > STATE->sent || STATE->stage == JABBER_CONNECTED)
           && (uip_newdata() || uip_acked() || uip_connected()))
    jabber_send_data(STATE->stage, STATE->action);
  else if (STATE->stage == JABBER_CONNECTED && uip_poll() && STATE->action)
    jabber_send_data(STATE->stage, STATE->action);

}
Beispiel #16
0
void user_quit() {
    // Part all channels
    user_quitAllChannels(CURRENT_ID);

    // Kill user
    user_reset();
    INFO->state = IRCD_STATE_DISCONNECTED;

    uip_close();
}
Beispiel #17
0
int16_t parse_cmd_bootloader(char *cmd, char *output, uint16_t len)
{
    (void) cmd;
    (void) output;
    (void) len;

    status.request_bootloader = 1;
#   ifdef UIP_SUPPORT
    uip_close();
#   endif
    return ECMD_FINAL_OK;
}
Beispiel #18
0
void uip_xtcpd_handle_poll(xtcpd_state_t *s)
{
    if (s->s.abort_request) {
        if (uip_udpconnection()) {
            uip_udp_conn->lport = 0;
            xtcpd_event(XTCP_CLOSED, s);
        }
        else
            uip_abort();
        s->s.abort_request = 0;
    }
    else if (s->s.close_request) {
        if (uip_udpconnection()) {
            uip_udp_conn->lport = 0;
            xtcpd_event(XTCP_CLOSED, s);
        }
        else
            uip_close();
        s->s.close_request = 0;
    }
    else if (s->s.connect_request) {
        if (uip_udpconnection()) {
            xtcpd_init_state(s,
                             XTCP_PROTOCOL_UDP,
                             (unsigned char *) uip_udp_conn->ripaddr,
                             uip_udp_conn->lport,
                             uip_udp_conn->rport,
                             uip_udp_conn);
            xtcpd_event(XTCP_NEW_CONNECTION, s);
            s->s.connect_request = 0;
        }
    }
    else if (s->s.send_request) {
        int len;
        if (s->linknum != -1) {
            xtcpd_service_clients_until_ready(s->linknum, xtcp_links, xtcp_num);
            len = xtcpd_send(xtcp_links[s->linknum],
                             XTCP_REQUEST_DATA,
                             s,
                             uip_appdata,
                             uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
            uip_send(uip_appdata, len);
        }
        s->s.send_request--;
    }
    else if (s->s.poll_interval != 0 &&
             timer_expired(&(s->s.tmr)))
    {
        xtcpd_event(XTCP_POLL, s);
        timer_set(&(s->s.tmr), s->s.poll_interval);
    }
}
Beispiel #19
0
/* next_sciptstate:
 *
 * Reads one line of script and decides what to do next.
 */
static void
next_scriptstate(void)
{
  struct httpd_fs_file fsfile;
  u8_t i;

 again:
  switch(hs->script[0]) {
  case ISO_t:
    /* Send a text string. */
    hs->state = HTTP_TEXT;
    hs->dataptr = &hs->script[2];

    /* Calculate length of string. */
    for(i = 0; hs->dataptr[i] != ISO_nl; ++i);
    hs->count = i;    
    break;
  case ISO_c:
    /* Call a function. */
    hs->state = HTTP_FUNC;
    hs->dataptr = NULL;
    hs->count = 0;
    uip_reset_acked();
    break;
  case ISO_i:   
    /* Include a file. */
    hs->state = HTTP_FILE;
    if(!httpd_fs_open(&hs->script[2], &fsfile)) {
      uip_abort();
      dealloc_state(hs);
    }
    hs->dataptr = fsfile.data;
    hs->count = fsfile.len;
    break;
  case ISO_hash:
    /* Comment line. */
    next_scriptline();
    goto again;
    break;
  case ISO_period:
    /* End of script. */
    hs->state = HTTP_END;
    uip_close();
    dealloc_state(hs);
    break;
  default:
    uip_abort();
    dealloc_state(hs);
    break;
  }
}
Beispiel #20
0
int16_t parse_cmd_reset(char *cmd, char *output, uint16_t len)
{
    (void) output;
    (void) len;

    if (*cmd != '\0')
	    return ECMD_ERR_PARSE_ERROR;

    status.request_reset = 1;
#ifdef UIP_SUPPORT
    uip_close();
#endif
    return ECMD_FINAL_OK;
}
/*-----------------------------------------------------------------------------------*/
void
specserver_appcall(void)
{
	static uint8_t reqs = 0; static char *data;
	if( uip_conn->lport != HTONS( SPECIAL_SERVER_PORT ) ) return; 
	specserver_stats.frames++;

	if( uip_connected() ) {
		reqs = 0;
	}
	if( uip_newdata() ) {
		specserver_stats.recv++;
		char *p;
		// Process response
		data = (char*)uip_appdata;
		p = strchr( data, '\r' ); if( p != NULL ) *p = 0;
		p = strchr( data, '\n' ); if( p != NULL ) *p = 0;
		data[50] = 0;	// Limit max size to one line or 50 char, whicever is smaller
		reqs++;
	}
	if( uip_acked() ) {
	}
	if( uip_rexmit() ||
		uip_newdata() ||
		uip_acked()) {
		// Send response
		if( reqs > 0 ) {
			reqs--;
			uip_send( specserver_resp_data, specserver_resp_data_len );
		}else{
			uip_close();
		}
	} else if(uip_poll()) {
		uip_close();
	}
}
Beispiel #22
0
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);

#if DEBUGLOGIC
   strcpy_P(s->filename,PSTR("/x"));
#endif
#if FIND_THE_SCRIPT
  s->script = httpd_simple_get_script(&s->filename[1]);
  if(s->script == NULL) {
    printf_P(PSTR("not found!"));
    strcpy_P(s->filename, PSTR("/notfound.html"));

    PT_WAIT_THREAD(&s->outputpt,
                   send_headers(s, http_header_404));
    PT_WAIT_THREAD(&s->outputpt,
                   send_string_P(s, NOT_FOUND));
    uip_close();

    PT_EXIT(&s->outputpt);
  } else {
#else
  s->script = generate_routes;
  if (1) {
#endif

    PT_WAIT_THREAD(&s->outputpt,
                   send_headers(s, http_header_200));
    PT_WAIT_THREAD(&s->outputpt, s->script(s));
  }
  s->script = NULL;
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
/*---------------------------------------------------------------------------*/
static void
handle_connection(struct httpd_state *s)
{
#if DEBUGLOGIC
  handle_output(s);
#else
  handle_input(s);
  if(s->state == STATE_OUTPUT) {
    handle_output(s);
  }
#endif
}
Beispiel #23
0
static void
mysql_main(void)
{
    if (uip_aborted() || uip_timedout()) {
	MYDEBUG ("connection aborted\n");
	mysql_conn = NULL;
    }

    if (uip_closed()) {
	MYDEBUG ("connection closed\n");
	mysql_conn = NULL;
    }

    if (uip_connected()) {
	MYDEBUG ("new connection\n");
	STATE->stage = MYSQL_WAIT_GREETING;
	STATE->sent = MYSQL_WAIT_GREETING;
	STATE->packetid = 0;
    }

    if (uip_newdata() && uip_len) {
#ifdef DEBUG_MYSQL
	MYDEBUG ("received data: %s\n", uip_appdata);
	for (uint16_t i = 0; i < uip_len; i ++)
	    debug_putchar (((unsigned char *) uip_appdata)[i]);
	debug_putchar (10);
#endif

	if (mysql_parse ()) {
	    uip_close ();		/* Parse error */
	    return;
	}
    }

    if (uip_rexmit()) {
	STATE->packetid --;
	mysql_send_data (STATE->sent);
    }
    else if ((STATE->stage > STATE->sent || STATE->stage == MYSQL_CONNECTED)
	     && (uip_newdata()
		 || uip_acked()
		 || uip_connected()))
	mysql_send_data (STATE->stage);
    else if (STATE->stage == MYSQL_CONNECTED
	     && uip_poll() && *STATE->u.stmtbuf)
	mysql_send_data(STATE->stage);

}
Beispiel #24
0
void
httpd_handle_404 (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_404);
    PASTE_P (httpd_header_length);
    PASTE_LEN_P (httpd_body_404);
    PASTE_P (httpd_header_end);
    PASTE_P (httpd_body_404);
    PASTE_SEND ();
}
void
httpd_handle_websocket (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_opt);
    //PASTE_P (httpd_header_length);
    //PASTE_LEN_P (httpd_body_opt);
    PASTE_P (httpd_header_end);
    //PASTE_P (httpd_body_opt);
    PASTE_SEND ();
}
Beispiel #26
0
void samb_appcall(void)
{
	int len;
	char buf[64];
	int i;
	unsigned int nomer_sambung = (unsigned int) uip_conn->nomer_sambung;
	
	if (nomer_sambung > 19)
	{
		//printf("Nomer sambung invalid !");
		debug_out_h("Nomer sambung invalid !");
		uip_close();
		return;	
	}
	
	//struct sambungan_state *sb = (struct sambungan_state *) &(uip_conn->appstate2);
	char ipne[32];
	
	/*
	sprintf(ipne, " [%d][%d]:%d.%d.%d.%d", nomer_sambung, uip_conn->lport, \
			htons(uip_conn->ripaddr[0]) >> 8, htons(uip_conn->ripaddr[0]) & 0xFF, \
			htons(uip_conn->ripaddr[1]) >> 8, htons(uip_conn->ripaddr[1]) & 0xFF );
	
	loop_kirim++;
	printf("\n * %d:%s", loop_kirim, ipne);
	*/
	if (uip_connected())
	{
		//printf("konek %s\n", ipne);
		if (status[nomer_sambung].stat == 1)
		{
			status[nomer_sambung].stat = 2;
			
			sprintf(ipne, " [%d][%d]:%d.%d.%d.%d", nomer_sambung+1, uip_conn->lport, \
			htons(uip_conn->ripaddr[0]) >> 8, htons(uip_conn->ripaddr[0]) & 0xFF, \
			htons(uip_conn->ripaddr[1]) >> 8, htons(uip_conn->ripaddr[1]) & 0xFF );
			
			//sprintf(buf, "sampurasun");
			
			/* sampurasun + nomor modul (dalam karakter) */
			sprintf(buf, "sampurasun%d", (char) sumber[nomer_sambung].alamat);	
			debug_out_h("%s->%s", buf, ipne);
					
			uip_send((char *) buf, 11);		// 10
		}
		else
		{
Beispiel #27
0
static void
httplog_net_main(void)
{
  if (uip_aborted() || uip_timedout())
  {
    HTTPLOG_DEBUG("connection aborted\n");
    goto end;
  }

  if (uip_closed())
  {
    HTTPLOG_DEBUG("connection closed\n");
    goto end;
  }


  if (uip_connected() || uip_rexmit())
  {
    HTTPLOG_DEBUG("new connection or rexmit, sending message\n");
    char *p = uip_appdata;
    p += sprintf_P(p, get_string_head);
#ifdef CONF_HTTPLOG_INCLUDE_UUID
    p += sprintf_P(p, uuid_string);
#endif
#ifdef CONF_HTTPLOG_INCLUDE_TIMESTAMP
    p += sprintf_P(p, time_string);
    p += sprintf(p, "%lu&", clock_get_time());
#endif
    p += sprintf(p, httplog_tmp_buf);
    p += sprintf_P(p, get_string_foot);
    uip_udp_send(p - (char *) uip_appdata);
    HTTPLOG_DEBUG("send %d bytes\n", p - (char *) uip_appdata);
  }

  if (uip_acked())
  {
    uip_close();
  end:
    if (httplog_tmp_buf)
    {
      free(httplog_tmp_buf);
      httplog_tmp_buf = NULL;
    }
  }
}
Beispiel #28
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);
  }
}
Beispiel #29
0
/*---------------------------------------------------------------------------*/
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();
  }
}
Beispiel #30
0
static void
sms77_net_main(void)
{	
	
    if (uip_aborted() || uip_timedout()) {
	SMSDEBUG ("connection aborted\n");
        if (sms77_tmp_buf) {
          free(sms77_tmp_buf);
          sms77_tmp_buf = NULL;
        }
        return;
    }

    if (uip_closed()) {
	SMSDEBUG ("connection closed\n");
        if (sms77_tmp_buf) {
          free(sms77_tmp_buf);
          sms77_tmp_buf = NULL;
        }
        return;
    }


    if (uip_connected() || uip_rexmit()) {
	SMSDEBUG ("new connection or rexmit, sending message\n");
        char *p = uip_appdata;
        p += sprintf(p,  "GET /?u=%s&p=%s&to=%s&type=%s&text=", sms77_user, sms77_pass, sms77_recv, sms77_type);
        p += urlencode(sms77_tmp_buf, strlen(sms77_tmp_buf), p);
        p += sprintf_P(p, sms77_secheader);
        uip_udp_send(p - (char *)uip_appdata);
        SMSDEBUG("send %d bytes\n", p - (char *)uip_appdata);
    }

    if (uip_acked()) {
      uip_close();
    }
    
    if (uip_newdata())
    	SMSDEBUG("data: %s\n", uip_appdata);

}