Esempio n. 1
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighbors(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  for(s->u.ptr = nbr_table_head(ds6_neighbors);
      s->u.ptr != NULL;
      s->u.ptr = nbr_table_next(ds6_neighbors, s->u.ptr)) {
    PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
  }

  PSOCK_GENERATOR_SEND(&s->sout, make_neighbor_roomfor, s);
  PSOCK_END(&s->sout);
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
static PT_THREAD (send_file (struct httpd_state *s))
{
  PSOCK_BEGIN (&s->sout);

  do 
  {
    PSOCK_GENERATOR_SEND (&s->sout, generate_part_of_file, s);
    s->file.len -= s->len;
    s->file.data += s->len;
  } 
  while (s->file.len > 0);

  PSOCK_END (&s->sout);
}
Esempio n. 3
0
static
PT_THREAD(send_buf(struct httpd_ws_state *s))
{
	memcpy(s->outbuf, buf, HTTPD_OUTBUF_SIZE);
	s->outbuf_pos = strlen(buf);
	buf_lock = 0;

	PSOCK_BEGIN(&s->sout);
	if(s->outbuf_pos > 0) {
		SEND_STRING(&s->sout, s->outbuf, s->outbuf_pos);
		s->outbuf_pos = 0;
	}
	PSOCK_END(&s->sout);
}
Esempio n. 4
0
static PT_THREAD(handle_connection(struct psock *p))
{
    static char buf[100];
    PSOCK_BEGIN(p);

    snprintf(buf, sizeof(buf), "%02X:%02X		temperature: %d\n\r",
             rimeaddr_node_addr.u8[0],
             rimeaddr_node_addr.u8[1],
             temperature_sensor.value(0)/10);

    PSOCK_SEND_STR(p, buf);

    PSOCK_END(p);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(create_test_session(struct psock *p))
{
  /*
   * A protosocket's protothread must start with a PSOCK_BEGIN(), with
   * the protosocket as argument.
   */
  PSOCK_BEGIN(p);

  /*
   * Here we define all the thread local variables that we need to
   * utilize.
   */
  static RequestSession request;
  static AcceptSession accept;
  
  PSOCK_WAIT_UNTIL(p,PSOCK_NEWDATA(p));
  if(PSOCK_NEWDATA(p)){
    /*
     * We read data from the buffer now that it has arrived.
     * Using memcpy we store it in our local variable.
     */
    PSOCK_READBUF(p);
    memcpy(&request,buffer,sizeof(request));

    TEST_AMOUNT = (int) request.NumOfPackets;
    UDP_SENDER_PORT = (int) request.SenderPort;
    UDP_RECEIVER_PORT = (int) request.RecieverPort;
    
    /*
     * Prints for debugging.
     */
    printf("Type: %"PRIu32"\n",request.Type);
    printf("SenderPort: %"PRIu32"\n",request.SenderPort);
    printf("ReceiverPort: %"PRIu32"\n",request.RecieverPort);
    printf("SenderAddress: %08x,%x\n",request.SenderAddress,request.SenderMBZ);
    printf("ReceiverAddress: %08x,%x\n",request.RecieverAddress,request.RecieverMBZ);
    printf("StartTime: %u\n",request.StartTime.Second);
    
    accept.Accept = 0;
    accept.Port = request.RecieverPort; 

    PSOCK_SEND(p, &accept, sizeof(accept));
    PSOCK_SEND(p, &accept, sizeof(accept));
  } else {
    printf("Timed out!\n");
  }  
  state = 3;
  PSOCK_END(p);
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))
{

  PSOCK_BEGIN(&s->sout);

  for(s->count = 0; s->count < UIP_CONNS; ++s->count) {
    if((uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
      PSOCK_GENERATOR_SEND(&s->sout, generate_tcp_stats, s);
    }
  }

  PSOCK_END(&s->sout);
}
Esempio n. 7
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int
handle_connection(struct hello_world_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n");
  PSOCK_READTO(&s->p, '\n');
  strncpy(s->name, s->inputbuffer, sizeof(s->name));
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, s->name);
  PSOCK_CLOSE(&s->p);
  
  PSOCK_END(&s->p);
}
Esempio n. 8
0
static PT_THREAD( net_stats ( struct httpd_state *s, char *ptr ) )
{
	PSOCK_BEGIN( &s->sout );
	( void ) ptr;
#if UIP_STATISTICS
	for( s->count = 0; s->count < sizeof(uip_stat) / sizeof(uip_stats_t); ++s->count )
	{
		PSOCK_GENERATOR_SEND( &s->sout, generate_net_stats, s );
	}

#endif /* UIP_STATISTICS */

	PSOCK_END( &s->sout );
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(routes(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  for(s->u.ptr = uip_ds6_route_head();
      s->u.ptr != NULL;
      s->u.ptr = uip_ds6_route_next(s->u.ptr)) {
    PSOCK_GENERATOR_SEND(&s->sout, make_route, s);
  }
  PSOCK_GENERATOR_SEND(&s->sout, make_routes_roomfor, s);

  PSOCK_END(&s->sout);
}
Esempio n. 10
0
static
PT_THREAD(handle_connection(struct psock *p))
{
  PSOCK_BEGIN(p);
  //PSOCK_SEND_STR(p, "Type something!\n");
  leds_on(LEDS_RED);
  PSOCK_READTO(p, '\n');
  printf("RX=%s", buf);
  //PSOCK_SEND_STR(p, "Got: ");
  //PSOCK_SEND(p, buf, PSOCK_DATALEN(p));
  //PSOCK_SEND_STR(p, "EOL\r\n");
  //PSOCK_CLOSE(p);
  PSOCK_END(p);
}
Esempio n. 11
0
static
PT_THREAD(handle_emu_in(struct httpd_state *s, RoverAction last)) {
	static int c = 0;
	PSOCK_BEGIN(&s->sin);
	
	f(8, "Input______________ ", &c);
	PSOCK_READTO(&s->sin, 0xFF);
	f(8, "Input ", &c);
	//int len = PSOCK_DATALEN(&s->sin)-1;
	// Report the data we got
	gotData(last, s->inputbuf);
	s->state = STATE_WAITING;
	
	PSOCK_END(&s->sin);
}
Esempio n. 12
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s){
  PSOCK_BEGIN(&s->p);
  while(1){
	PSOCK_READTO(&s->p, '\n');
	if(*s->inputbuffer=='q'){
		PSOCK_SEND_STR(&s->p, "\n");
		break;
	}
	handleCommand(s->inputbuffer, s->outputbuffer);
	memset(s->inputbuffer, 0x00, SOCKET_BUFFER_LENGTH);
	PSOCK_SEND_STR(&s->p, s->outputbuffer);
  }
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Esempio n. 13
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(rplroot(struct httpd_state *s, char *ptr))
{
  int ret;
  PSOCK_BEGIN(&s->sout);
  ret = simple_rpl_init_dag_immediately();
  if(ret == 0) {
    PSOCK_SEND_STR(&s->sout, "Becomming RPL root of the network...");
  } else if(ret == -1) {
    PSOCK_SEND_STR(&s->sout, "Failed to create a RPL root: no local address found");
  } else if(ret == -2) {
    PSOCK_SEND_STR(&s->sout, "Failed to create a RPL root: no preferred address found");
  }
  PSOCK_END(&s->sout);
}
Esempio n. 14
0
static PT_THREAD(SendData(struct httpd_state *s, int len, char* b)) {
	static int c = 0;
	
	PSOCK_BEGIN(&s->sout);
	f(7, "SendData___________________ ", &c);
	PSOCK_SEND(&s->sout, b, len);
	f(7, "SendData ", &c);
	
	if (s->state == STATE_OUTPUT) {
		s->state = STATE_WAITING;
	} else { // if == STATE_OUTPUT_READBACK
		s->state = STATE_READBACK;
	}
	PSOCK_END(&s->sout);
}
Esempio n. 15
0
/*---------------------------------------------------------------------------*/
static PT_THREAD (handle_input (struct httpd_state *s))
{
  PSOCK_BEGIN (&s->sin);

  PSOCK_READTO (&s->sin, ISO_space);

  if (strncmp (s->inputbuf, http_get, 4) != 0)
    PSOCK_CLOSE_EXIT (&s->sin);
  
  PSOCK_READTO (&s->sin, ISO_space);

  if (s->inputbuf [0] != ISO_slash)
    PSOCK_CLOSE_EXIT (&s->sin);

  if (s->inputbuf [1] == ISO_space)
    strncpy (s->filename, http_index_html, sizeof (s->filename));
  else 
  {
    char *c;

    s->inputbuf [PSOCK_DATALEN (&s->sin) - 1] = 0;

    if ((c = strstr (s->inputbuf, "?")))
      *c++ = '\0';

    strncpy (s->filename, &s->inputbuf [0], sizeof (s->filename));

    if (!strcmp (s->filename, "/led.shtml"))
    {
      if (c && strstr (c, "LED2=1"))
        GPIO0_FIOCLR = GPIO_IO_P11;
      else
        GPIO0_FIOSET = GPIO_IO_P11;
    }
  }

  s->state = STATE_OUTPUT;

  while (1) 
  {
    PSOCK_READTO (&s->sin, ISO_nl);

    if (strncmp (s->inputbuf, http_referer, 8) == 0)
      s->inputbuf [PSOCK_DATALEN (&s->sin) - 2] = 0;
  }

  PSOCK_END (&s->sin);
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(generate_routes(struct httpd_state *s))
{
  static int i;
  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);

  blen = 0;
  ADD("Neighbors<pre>");
  for(i = 0; i < UIP_DS6_NBR_NB; i++) {
    if(uip_ds6_nbr_cache[i].isused) {
      ipaddr_add(&uip_ds6_nbr_cache[i].ipaddr);
      ADD("\n");
      if(blen > sizeof(buf) - 45) {
        SEND_STRING(&s->sout, buf);
        blen = 0;
      }
    }
  }

  ADD("</pre>Routes<pre>");
  SEND_STRING(&s->sout, buf);
  blen = 0;
  for(i = 0; i < UIP_DS6_ROUTE_NB; i++) {
    if(uip_ds6_routing_table[i].isused) {
      ipaddr_add(&uip_ds6_routing_table[i].ipaddr);
      ADD("/%u (via ", uip_ds6_routing_table[i].length);
      ipaddr_add(&uip_ds6_routing_table[i].nexthop);
      if(uip_ds6_routing_table[i].state.lifetime < 600) {
        ADD(") %lus\n", uip_ds6_routing_table[i].state.lifetime);
      } else {
        ADD(")\n");
      }
      SEND_STRING(&s->sout, buf);
      blen = 0;
    }
  }
  ADD("</pre>");
//if(blen > 0) {
    SEND_STRING(&s->sout, buf);
// blen = 0;
//}

  SEND_STRING(&s->sout, BOTTOM);

  PSOCK_END(&s->sout);
}
Esempio n. 17
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {

    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;

    /* Process any form input being sent to the server. */
    {
        // Form input called here
        extern void vApplicationProcessFormInput( char *pcInputString, long xInputLength );
        vApplicationProcessFormInput( s->inputbuf, PSOCK_DATALEN(&s->sin) );
    }

    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  /*  httpd_log_file(uip_conn->ripaddr, s->filename);*/
  
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      /*      httpd_log(&s->inputbuf[9]);*/
    }
  }
  
  PSOCK_END(&s->sin);
}
Esempio n. 18
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(routesping(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  for(s->u.ptr = uip_ds6_route_head();
      s->u.ptr != NULL;
      s->u.ptr = uip_ds6_route_next(s->u.ptr)) {
    uip_ds6_route_t *r = (uip_ds6_route_t*) s->u.ptr;
    simple_udp_ping_send_ping(&r->ipaddr);
    PSOCK_GENERATOR_SEND(&s->sout, make_route, s);
  }
  PSOCK_GENERATOR_SEND(&s->sout, make_routes_roomfor, s);

  PSOCK_END(&s->sout);
}
Esempio n. 19
0
/*---------------------------------------------------------------------------*/
static int
handle_connection(struct psock *p)
{
  PSOCK_BEGIN(p);

  PSOCK_SEND_STR(p, "GET / HTTP/1.0\r\n");
  PSOCK_SEND_STR(p, "Server: Contiki example protosocket client\r\n");
  PSOCK_SEND_STR(p, "\r\n");

  while(1) {
    PSOCK_READTO(p, '\n');
    printf("Got: %s", buffer);
  }
  
  PSOCK_END(p);
}
Esempio n. 20
0
static
PT_THREAD(send_values(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);

  if(strncmp(s->filename, "/index", 6) == 0 ||
     s->filename[1] == '\0') {
    /* Default page: show latest sensor values as text (does not
       require Internet connection to Google for charts). */
    blen = 0;
    ADD("<h1>Websense</h1>\n");
#if CONTIKI_TARGET_SKY
    ADD("<h2>Current readings</h2>\n"
        "Light: %u<br>"
        "Temperature: %u&deg; C",
        get_light(), get_temp());
#endif
    SEND_STRING(&s->sout, buf);
  } else if(s->filename[1] == '0') {
    /* Turn off leds */
    leds_off(LEDS_ALL);
    SEND_STRING(&s->sout, "Turned off leds!");

  } else if(s->filename[1] == '1') {
    /* Turn on leds */
    leds_on(LEDS_ALL);
    SEND_STRING(&s->sout, "Turned on leds!");

  } else {
#if CONTIKI_TARGET_SKY
    if(s->filename[1] != 't') {
      generate_chart("Light", "Light", 0, 500, light1);
      SEND_STRING(&s->sout, buf);
    }
    if(s->filename[1] != 'l') {
      generate_chart("Temperature", "Celsius", 15, 50, temperature);
      SEND_STRING(&s->sout, buf);
    }
#endif
  }

  SEND_STRING(&s->sout, BOTTOM);

  PSOCK_END(&s->sout);
}
Esempio n. 21
0
static int handle_connection(struct webserver_state *s)
{
	PSOCK_BEGIN(&s->p);

	// the incoming GET request will have the following format:
	// GET / HTTP/1.1 ....
	// we have to parse this string to determine the resource being requested
	// if the requested resource is not the root webpage ('/') then,
	// GET /<resource name> HTTP/1.1 ....
	// we should parse the specific resource and react appropriately

	// read incoming data until we read a space character
	PSOCK_READTO(&s->p, ISO_space);

	// parse the data to determine if it was a GET request
	if(strncmp(s->inputbuf, http_get, 4) != 0) {
		PSOCK_CLOSE_EXIT(&s->p);
	}

	// continue reading until the next space character
	PSOCK_READTO(&s->p, ISO_space);

	// determine the requested resource
	// in this case, we check if the request was for the '/' root page
	// AKA index.html
	if(s->inputbuf[0] != ISO_slash) {
		// request for unknown webpage, close and exit
		PSOCK_CLOSE_EXIT(&s->p);
	}

	if(s->inputbuf[1] != ISO_space) {
		// request for unavailable resource
		// not supported, modify to add support for additional resources
		PSOCK_CLOSE_EXIT(&s->p);
	}

	lockstate = lockstate+1;

        PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
	PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
	PSOCK_SEND_STR(&s->p, "\r\n");
	PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
	PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am Matt's WiShield.  Find me in webserver.c under PSOCK_SEND_STR.</h1></center>");
        PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
	PSOCK_CLOSE(&s->p);
	PSOCK_END(&s->p);
}
Esempio n. 22
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(nodeidcall(struct httpd_state *s, char *ptr))
{
  static char buf[24];
  PSOCK_BEGIN(&s->sout);
  snprintf(buf, sizeof(buf), "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
	   rimeaddr_node_addr.u8[0],
       rimeaddr_node_addr.u8[1],
       rimeaddr_node_addr.u8[2],
       rimeaddr_node_addr.u8[3],
       rimeaddr_node_addr.u8[4],
       rimeaddr_node_addr.u8[5],
       rimeaddr_node_addr.u8[6],
       rimeaddr_node_addr.u8[7]);
  PSOCK_SEND_STR(&s->sout, buf);
  PSOCK_END(&s->sout);
}
Esempio n. 23
0
static
PT_THREAD(send_values(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);

  SEND_STRING(&s->sout, TOP);

  if(strncmp(s->filename, "/index", 6) == 0 ||
     s->filename[1] == '\0') {
    /* Default page: show latest sensor values as text (does not
       require Internet connection to Google for charts). */
    blen = 0;
    float mybatt = get_mybatt();
    float mytemp = get_mytemp();
    ADD("<h1>Current readings</h1>\n"
        "Battery: %ld.%03d V<br>"
        "Temperature: %ld.%03d &deg; C",
        (long) mybatt, (unsigned) ((mybatt-floor(mybatt))*1000), 
        (long) mytemp, (unsigned) ((mytemp-floor(mytemp))*1000)); 
    SEND_STRING(&s->sout, buf);

  } else if(s->filename[1] == '0') {
    /* Turn off leds */
    leds_off(LEDS_ALL);
    SEND_STRING(&s->sout, "Turned off leds!");

  } else if(s->filename[1] == '1') {
    /* Turn on leds */
    leds_on(LEDS_ALL);
    SEND_STRING(&s->sout, "Turned on leds!");

  } else {
    if(s->filename[1] != 't') {
      generate_chart("Battery", "mV", 0, 4000, battery1);
      SEND_STRING(&s->sout, buf);
    }
    if(s->filename[1] != 'b') {
      generate_chart("Temperature", "Celsius", 0, 50, temperature);
      SEND_STRING(&s->sout, buf);
    }
  }

  SEND_STRING(&s->sout, BOTTOM);

  PSOCK_END(&s->sout);
}
Esempio n. 24
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
  
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_htm, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
  }
#endif /* URLCONV */

  petsciiconv_topetscii(s->filename, sizeof(s->filename));
  webserver_log_file(&uip_conn->ripaddr, s->filename);
  petsciiconv_toascii(s->filename, sizeof(s->filename));
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
  }
  
  PSOCK_END(&s->sin);
}
Esempio n. 25
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  // GET Request
  if(!strncmp(s->inputbuf, http_get, 4)) {
  //PSOCK_CLOSE_EXIT(&s->sin);
		s->method = GET;
  } else {
		s->method = POST;
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
#endif /* URLCONV */

  //webserver_log_file(&uip_conn->ripaddr, s->filename);

  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);
#if 0
    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      webserver_log(s->inputbuf);
    }
#endif
  }

  PSOCK_END(&s->sin);
}
Esempio n. 26
0
int handle_connection(webserver_state* s) {
  PSOCK_BEGIN(&s->p);

  // Read HTTP verb (e.g. GET/POST) - and ignore it.
  PSOCK_READTO(&s->p, ' ');
  // Read requested path (up to next space)
  PSOCK_READTO(&s->p, ' ');

  RESPOND_STR(s, "HTTP/1.1 200 OK\r\n");
  RESPOND_STR(s, "Content-Type: text/plain\r\n");
  RESPOND_STR(s, "\r\n");

  if (STR_EQ(s->inputbuf, "/ ")) {
    // no-op, just for testing
    RESPOND_STR(s, "test");
  } else if (STR_EQ(s->inputbuf, "/comcast ")) {
    room.watchComcast();
    RESPOND_STR(s, "comcast");
  } else if (STR_EQ(s->inputbuf, "/dvd ")) {
    room.watchDvd();
    RESPOND_STR(s, "dvd");
  } else if (STR_EQ(s->inputbuf, "/roku ")) {
    room.streamRoku();
    RESPOND_STR(s, "roku");
  } else if (STR_EQ(s->inputbuf, "/ps3 ")) {
    room.playPlaystation();
    RESPOND_STR(s, "ps3");
  } else if (STR_EQ(s->inputbuf, "/cd ")) {
    room.listenCd();
    RESPOND_STR(s, "cd");
  } else if (STR_EQ(s->inputbuf, "/off ")) {
    room.allOff();
    RESPOND_STR(s, "off");
  } else if (STR_EQ(s->inputbuf, "/reset ")) {
    room.forceReset();
    RESPOND_STR(s, "reset");
  } else {
    RESPOND_STR(s, "unknown");
  }

  RESPOND_STR(s, "\r\n");
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Esempio n. 27
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
	//printf("http 1: %s\r\n", s->inputbuf);
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
	
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);
  //printf("http 2: %s\r\n", s->inputbuf);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  //*  
   //httpd_log_file(uip_conn->ripaddr, s->filename);
  //*/
  
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      /*      httpd_log(&s->inputbuf[9]);*/
    }
  }
  
  PSOCK_END(&s->sin);
  //nEth = 0;
}
Esempio n. 28
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighborscall(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  announcement_listen(1);
  
  /*  printf("neighbor_num %d\n", collect_neighbor_list_num(&neighbor_list)); */
  
  for(s->u.count = 0; s->u.count < collect_neighbor_list_num(&neighbor_list); s->u.count++) {
    /*  printf("count %d\n", s->u.count); */
    if(collect_neighbor_list_get(&neighbor_list, s->u.count) != NULL) {
      /*  printf("!= NULL\n"); */
      PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
    }
  }

  PSOCK_END(&s->sout);
}
Esempio n. 29
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_file(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sout);
  
  do {
    /* Read data from file system into buffer */
    s->len = cfs_read(s->fd, s->outputbuf, sizeof(s->outputbuf));

    /* If there is data in the buffer, send it */
    if(s->len > 0) {
      PSOCK_SEND(&s->sout, (uint8_t *)s->outputbuf, s->len);
    } else {
      break;
    }
  } while(s->len > 0);
      
  PSOCK_END(&s->sout);
}
Esempio n. 30
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
static PT_THREAD(send_headers (struct httpd_state *s, const char *statushdr))
{
	/*~~~~~~~~~*/
	char	*ptr;
	/*~~~~~~~~~*/

	PSOCK_BEGIN(&s->sout);

	PSOCK_SEND_STR(&s->sout, statushdr);

	ptr = strrchr(s->filename, ISO_period);
	if(ptr == NULL)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_binary);
	}
	else if(strncmp(http_html, ptr, 5) == 0 || strncmp(http_shtml, ptr, 6) == 0)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_html);
	}
	else if(strncmp(http_css, ptr, 4) == 0)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_css);
	}
	else if(strncmp(http_png, ptr, 4) == 0)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_png);
	}
	else if(strncmp(http_gif, ptr, 4) == 0)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_gif);
	}
	else if(strncmp(http_jpg, ptr, 4) == 0)
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_jpg);
	}
	else
	{
		PSOCK_SEND_STR(&s->sout, http_content_type_plain);
	}

	PSOCK_END(&s->sout);
}