Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
static PT_THREAD(sensors_list(struct httpd_state *s, char *))
{

  PSOCK_BEGIN(&s->sout);

  for(s->count = 0; sensors[s->count].is_valid_P(); ++s->count) {
    PSOCK_GENERATOR_SEND(&s->sout, generate_sensors_list, s);
  }

  PSOCK_END(&s->sout);
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
{

  PSOCK_BEGIN(&s->sout);

  //while (pgm_read_byte(ptr++)!=' ') {};	//skip to "/filename" after the script invokation
  PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) (strchr_P(ptr, ' ') + 1));
  
  PSOCK_END(&s->sout);
}
Ejemplo n.º 4
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 );
}
Ejemplo n.º 5
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
{

  PSOCK_BEGIN(&s->sout);

  /* Pass string after cgi invocation to the generator */
  s->u.ptr = ptr;
  PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, s);
  
  PSOCK_END(&s->sout);
}
Ejemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
{

  PSOCK_BEGIN(&s->sout);

  thisfilename=&s->filename[0]; //temporary way to pass filename to generate_file_stats
  
  PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) ptr);
  
  PSOCK_END(&s->sout);
}
Ejemplo n.º 7
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(addrmap(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  for(s->u.ptr = ip64_addrmap_list();
      s->u.ptr != NULL;
      s->u.ptr = list_item_next(s->u.ptr)) {
    PSOCK_GENERATOR_SEND(&s->sout, make_addrmap, s);
  }

  PSOCK_END(&s->sout);
}
Ejemplo n.º 8
0
static PT_THREAD( net_stats ( struct httpd_state *s, char *ptr ) )
{
    PSOCK_BEGIN( &s->sout );

#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 );
}
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
0
static uint16_t handle_connection(struct simple_httpd_state *s)
{
	PSOCK_BEGIN(&s->p);

	int comp;

	// 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((comp = strncmp_P((const char *)(s->inputbuf), (const char *)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){
		PSOCK_CLOSE_EXIT(&s->p);				// request for unknown webpage, close and exit
	}

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

	PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0); 	// generate the web page response with fill_buf from PSTR variable

	PSOCK_CLOSE(&s->p);
	PSOCK_END(&s->p);
}
Ejemplo n.º 12
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(neighborsping(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);

  /* Ping nodes */
  for(s->u.ptr = nbr_table_head(ds6_neighbors);
      s->u.ptr != NULL;
      s->u.ptr = nbr_table_next(ds6_neighbors, s->u.ptr)) {
    uip_ipaddr_t *addr;
    uip_ds6_nbr_t *nbr= s->u.ptr;
    addr = uip_ds6_nbr_get_ipaddr(nbr);
    if(addr != NULL) {
      simple_udp_ping_send_ping(addr);
    }
    PSOCK_GENERATOR_SEND(&s->sout, make_neighbor, s);
  }

  PSOCK_END(&s->sout);
}
Ejemplo n.º 13
0
/***** VOLTAGE *****/
static
PT_THREAD(volt_stats(struct httpd_state *s, char *ptr))
{
  
  char *f = strchr(ptr, ' ') + 1; // pointer to "second" argument from xml file
  
  /* Character matching of "2nd argument" from XML file */
  #define REQ_ARGUMENT_LENGTH 4 // 4 is size of sample referencing specified in XML files!
  char sampleIndexStr[REQ_ARGUMENT_LENGTH + 1] = ""; //Remember +1 for NULL byte!
  strncat(sampleIndexStr, f+0, REQ_ARGUMENT_LENGTH);
  s->requestedNoOfSamples = atoi(sampleIndexStr); // This is relative so that "now" is zero and needs to be translated to circular buffer index.

  s->circularBufferLastWriteAtCallTime = voltageShortHistLastWriteIndex; //Save it in a httpd_state as this function will be interrupted and local variables can change
  
  PSOCK_BEGIN(&s->sout);

  /** generate functions gets called ONCE PER value at the moment **/
  for(s->count = 0;   s->count  <  s->requestedNoOfSamples;  ){//  ++s->count) { //expression3 is omitted and done put generate function!!!!
      PSOCK_GENERATOR_SEND(&s->sout, generate_volt_stats, s);
  }//for

  PSOCK_END(&s->sout);
}
Ejemplo n.º 14
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);
	
	#ifdef PAKAI_FILE_SIMPAN
	if ( s->file.flag == 27 )
	{
		//printf(" Close file\r\n");
		
		f_close( s->file.fd );
		
    }
    #endif
	
  PSOCK_END(&s->sout);
}
Ejemplo n.º 15
0
static PT_THREAD(led_io(struct httpd_state *s, char *ptr))
{
  PSOCK_BEGIN(&s->sout);
  PSOCK_GENERATOR_SEND(&s->sout, generate_io_state, NULL);
  PSOCK_END(&s->sout);
}
Ejemplo n.º 16
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{
  char *ptr;
  PSOCK_BEGIN(&s->sout);

  PSOCK_GENERATOR_SEND(&s->sout, generate_status, (char *) statushdr);

  ptr = strrchr(s->filename, ISO_period);
  if (httpd_strncmp("4", statushdr, 1) == 0) { //404
    PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_htm);
  } else if (ptr == NULL) {
#if WEBSERVER_CONF_BIN
    PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_bin);
#else
    PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_htm);
#endif 
  } else {
    ptr++;
#if WEBSERVER_CONF_INCLUDE || WEBSERVER_CONF_CGI
    if (httpd_strncmp(ptr, &httpd_mime_htm[5], 3) == 0 || httpd_strncmp(ptr, &httpd_str_shtml[1], 4) == 0) {
#else
    if (httpd_strncmp(ptr, &httpd_mime_htm[5], 3) == 0) {
#endif
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_htm);
#if WEBSEVER_CONF_CSS
    } else if (httpd_strcmp(ptr, &httpd_mime_css[5]) == 0) {
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_css);
#endif
#if WEBSERVER_CONF_PNG
    } else if (httpd_strcmp(ptr, &httpd_mime_png[6]) == 0) {
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_png);
#endif
#if WEBSERVER_CONF_GIF
    } else if (httpd_strcmp(ptr, &httpd_mime_gif[6]) == 0) {
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_gif);
#endif
#if WEBSERVER_CONF_JPG
    } else if (httpd_strcmp(ptr, httpd_mime_jpg) == 0) {
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_jpg);
#endif
#if WEBSERVER_CONF_TXT
    } else {
      PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_txt);
#endif
    }
  }
  PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  char *ptr;

  PT_BEGIN(&s->outputpt);

#if DEBUGLOGIC
  httpd_strcpy(s->filename, httpd_str_indexfn);
#endif

  s->fd = httpd_fs_open(s->filename, HTTPD_FS_READ);
  if (s->fd == -1) { // Opening file failed.

    /* TODO: try index.htm ? */
#if WEBSERVER_CONF_INCLUDE || WEBSERVER_CONF_CGI
    /* If index.html not found try index.htm */
    if (httpd_strcmp(s->filename, httpd_str_indexfn) == 0) {
      httpd_strcpy(s->filename, httpd_str_indexfn3);
    }
    s->fd = httpd_fs_open(s->filename, HTTPD_FS_READ);
    if (s->fd != -1) {
      goto sendfile;
    }
    /* If index.html not found try index.shtml */
    if (httpd_strcmp(s->filename, httpd_str_indexfn) == 0) {
      httpd_strcpy(s->filename, httpd_str_indexsfn);
    }
    s->fd = httpd_fs_open(s->filename, HTTPD_FS_READ);
    if (s->fd == -1) {
      PRINTD("Opening %s failed\n", s->filename);
      goto psock_close;
    } else {
      goto sendfile;
    }
#endif
    /* If nothing was found, send 404 page */
    httpd_strcpy(s->filename, httpd_str_404fn);
    s->fd = httpd_fs_open(s->filename, HTTPD_FS_READ);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_str_404notf));
    PT_WAIT_THREAD(&s->outputpt, send_file(s));

  } else { // Opening file succeeded.

sendfile:
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_str_200ok));
#if WEBSERVER_CONF_INCLUDE || WEBSERVER_CONF_CGI
    /* If filename ends with .shtml, scan file for script includes or cgi */
    ptr = strchr(s->filename, ISO_period);
    if ((ptr != NULL && httpd_strncmp(ptr, httpd_str_shtml, 6) == 0)
            || httpd_strcmp(s->filename, httpd_str_indexfn) == 0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_scripts(s));
    } else {
#else
    if (1) {
#endif
      PT_WAIT_THREAD(&s->outputpt, send_file(s));
      httpd_fs_close(s->fd);
    }
  }
psock_close:
  PSOCK_CLOSE(<y & s->sout);
  PT_END(&s->outputpt);
}
/*---------------------------------------------------------------------------*/
#if WEBSERVER_CONF_PASSQUERY
char httpd_query[WEBSERVER_CONF_PASSQUERY];
#endif

static
PT_THREAD(handle_input(struct httpd_state *s))
{

  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  if (httpd_strncmp(s->inputbuf, httpd_str_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) {
    httpd_strcpy(s->filename, httpd_str_indexfn);
  } else {
    uint8_t i;
    for (i = 0; i<sizeof (s->filename) + 1; i++) {
      if (i >= (PSOCK_DATALEN(&s->sin) - 1)) break;
      if (s->inputbuf[i] == ISO_space) break;
#if WEBSERVER_CONF_PASSQUERY
      /* Query string is left in the httpd_query buffer until zeroed by the application! */
      if (s->inputbuf[i] == ISO_qmark) {
        strncpy(httpd_query, &s->inputbuf[i + 1], sizeof (httpd_query));
        break;
      }
#endif
      s->filename[i] = s->inputbuf[i];
    }
    s->filename[i] = 0;
  }

#if WEBSERVER_CONF_LOG
  webserver_log_file(&uip_conn->ripaddr, s->filename);
  //  webserver_log(httpd_query);
#endif
#if WEBSERVER_CONF_LOADTIME
  s->pagetime = clock_time();
#endif
  s->state = STATE_OUTPUT;
  while (1) {
    PSOCK_READTO(&s->sin, ISO_nl);
#if WEBSERVER_CONF_LOG && WEBSERVER_CONF_REFERER
    if (httpd_strncmp(s->inputbuf, httpd_str_ref, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
#endif
  }
  PSOCK_END(&s->sin);
}
Ejemplo n.º 17
0
static
PT_THREAD(generate_routes(struct httpd_state *s))
{
  uint8_t i=0;
  PSOCK_BEGIN(&s->sout);

  PSOCK_GENERATOR_SEND(&s->sout, generate_string_P, (char *) TOP1);
  PSOCK_GENERATOR_SEND(&s->sout, generate_string_P, (char *) TOP2);

#if UIP_CONF_IPV6     //allow ip4 builds
  blen = 0;
  ADD("<h2>Neighbors [%u max]</h2>",UIP_DS6_NBR_NB);
  PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);  
  blen = 0;
  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("<br>");
//    if(blen > sizeof(buf) - 45) {
        PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);  
        blen = 0;
//    }
    }
  }

  ADD("<h2>Routes [%u max]</h2>",UIP_DS6_ROUTE_NB);
  PSOCK_GENERATOR_SEND(&s->sout, generate_string, 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);
 	  PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);
      blen=0;
      ipaddr_add(&uip_ds6_routing_table[i].nexthop);
      if(uip_ds6_routing_table[i].state.lifetime < 600) {
        PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);
        blen=0;
        ADD(") %lus<br>", uip_ds6_routing_table[i].state.lifetime);
      } else {
        ADD(")<br>");
      }
	  PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);  
      blen = 0;
    }
  }
  if(blen > 0) {
	PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);  
    blen = 0;
  }
#else /* UIP_CONF_IPV6 */
  blen = 0;i++;
  ADD("<h2>Hey, you got ip4 working!</h2>");
  PSOCK_GENERATOR_SEND(&s->sout, generate_string, buf);  
#endif /* UIP_CONF_IPV6 */

  PSOCK_GENERATOR_SEND(&s->sout, generate_string_P, (char *) BOTTOM);  

  PSOCK_END(&s->sout);
}