More reliable webserver-nano build

This commit is contained in:
David Kopf 2011-08-24 10:52:30 -04:00
parent 09db159876
commit c23abeb3ed
4 changed files with 66 additions and 11 deletions

View File

@ -1,2 +1,12 @@
webserver-nano_src = webserver-nogui.c httpd.c psock.c memb.c httpd-fs.c httpd-cgi.c
webserver-nano_dsc = webserver-dsc.c
#Run makefsdata to regenerate httpd-fsdata.c when web content has been edited. This requires PERL.
# Note: Deleting files or transferring pages from makefsdata.ignore will not trigger this rule
# when there is no change in modification dates.
$(CONTIKI)/apps/webserver-nano/httpd-fsdata.c : $(CONTIKI)/apps/webserver-nano/httpd-fs/*.*
$(CONTIKI)/tools/makefsdata -d $(CONTIKI)/apps/webserver-nano/httpd-fs -o $(CONTIKI)/apps/webserver-nano/httpd-fsdata.c
#Rebuild httpd-fs.c when makefsdata has changed httpd-fsdata.c
$(CONTIKI)/apps/webserver-nano/httpd-fs.c: $(CONTIKI)/apps/webserver-nano/httpd-fsdata.c
touch $(CONTIKI)/apps/webserver-nano/httpd-fs.c

View File

@ -88,9 +88,10 @@ static const char rtes_name[] HTTPD_STRING_ATTR = "routes";
#if WEBSERVER_CONF_TICTACTOE
static const char tictac_name[] HTTPD_STRING_ATTR = "tictac";
#endif
#endif
/*Process states for processes cgi*/
#endif
#if WEBSERVER_CONF_PROCESSES || WEBSERVER_CONF_TCPSTATS
static const char closed[] HTTPD_STRING_ATTR = "CLOSED";
static const char syn_rcvd[] HTTPD_STRING_ATTR = "SYN-RCVD";
@ -178,42 +179,58 @@ generate_header(void *arg)
{
unsigned short numprinted=0;
#if WEBSERVER_CONF_HEADER_W3C
#define _MSS1 100
static const char httpd_cgi_headerw[] HTTPD_STRING_ATTR = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerw);
#endif
#if WEBSERVER_CONF_HEADER_ICON
#define _MSS2 105
static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "<html><head><title>Contiki-nano</title><link rel=\"icon\" href=\"favicon.gif\" type=\"image/gif\"></head><body>";
#else
#define _MSS2 52
static const char httpd_cgi_header1[] HTTPD_STRING_ATTR = "<html><head><title>Contiki-nano</title></head><body>";
#endif
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_header1);
#if WEBSERVER_CONF_HEADER_MENU
#define _MSS3 32
static const char httpd_cgi_headerm1[] HTTPD_STRING_ATTR = "<pre><a href=\"/\">Front page</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm1);
#if WEBSERVER_CONF_SENSORS
#define _MSS4 34
static const char httpd_cgi_headerm2[] HTTPD_STRING_ATTR = "|<a href=\"status.shtml\">Status</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm2);
#endif
#if WEBSERVER_CONF_TCPSTATS
#define _MSS5 44
static const char httpd_cgi_headerm3[] HTTPD_STRING_ATTR = "|<a href=\"tcp.shtml\">Network connections</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm3);
#endif
#if WEBSERVER_CONF_PROCESSES
#define _MSS6 46
static const char httpd_cgi_headerm4[] HTTPD_STRING_ATTR = "|<a href=\"processes.shtml\">System processes</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm4);
#endif
#if WEBSERVER_CONF_FILESTATS
#define _MSS7 45
static const char httpd_cgi_headerm5[] HTTPD_STRING_ATTR = "|<a href=\"files.shtml\">File statistics</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm5);
#endif
#if WEBSERVER_CONF_TICTACTOE
#define _MSS8 44
static const char httpd_cgi_headerm6[] HTTPD_STRING_ATTR = "|<a href=\"/ttt/ttt.shtml\">TicTacToe</a>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerm6);
#endif
static const char httpd_cgi_headerme[] HTTPD_STRING_ATTR = "</pre>";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_headerme);
#endif /* WEBSERVER_CONF_MENU */
#if UIP_RECEIVE_WINDOW < _MSS1+_MSS2+_MSS3_+MSS4_+MSS5_MSS6+_MSS7+_MSS8
#warning ************************************************************
#warning UIP_RECEIVE_WINDOW not large enough for header cgi output.
#warning Web pages will not render properly!
#warning ************************************************************
#endif
return numprinted;
}
/*---------------------------------------------------------------------------*/
@ -546,6 +563,14 @@ generate_sensor_readings(void *arg)
m=s/60;
s=s-m*60;
numprinted+=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_sensor3, h,m,s);
/* TODO: some gcc's have a bug with %02d format that adds a zero byte and extra chars to the end of the string.
* Seen with arm-none-eabi-gcc.exe (Sourcery G++ Lite 2008q3-66) 4.3.2
* Quick cosmetic fix to strip that off: */
if (*(char *)(uip_appdata + numprinted-3)==0) {numprinted-=3;}
else if (*(char *)(uip_appdata + numprinted-2)==0) {numprinted-=2;}
else if (*(char *)(uip_appdata + numprinted-1)==0) {numprinted-=1;}
#if 0
if (sleepseconds) {
p1=100UL*sleepseconds/seconds;

View File

@ -43,8 +43,22 @@
* Firefox network.http.max-connections-per-server is set to a lower number.
* The RAM needed for each entry depends on script enabling and buffer sizes; see struct httpd_state below.
* Typical range is 100 - 200 bytes per connection
* cgi's that use PSOCK_GENERATOR_SEND will have truncated output if UIP_CONF_RECEIVE_WINDOW and UIP_CONF_TCP_MSS
* are not large enough. The header-menu cgi needs ~340 bytes if all options are enabled, while the file-stats * cgi
* can exceed any MSS if there are enough files to display (e.g. tic-tac-toe).
* The advertised MSS is easily seen in wireshark.
* Some example set a small MSS by default. rpl-border-router for example uses a receive window of 60.
*/
#ifndef WEBSERVER_CONF_NANO
#if CONTIKI_TARGET_SKY || CONTIKI_TARGET_STK500
#define WEBSERVER_CONF_NANO 1
#else
#define WEBSERVER_CONF_NANO 3
#endif
#endif
#if WEBSERVER_CONF_NANO==1
/* nano-size for constrained MCUs */
#define WEBSERVER_CONF_CONNS 2
#define WEBSERVER_CONF_NAMESIZE 16
#define WEBSERVER_CONF_BUFSIZE 40
@ -84,7 +98,12 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
/* Include referrer in log */
#define WEBSERVER_CONF_REFERER 0
#else /* !sky */
#elif WEBSERVER_CONF_NANO==2
/* webserver-mini having more content */
#error webserver-micro not implemented
#elif WEBSERVER_CONF_NANO==3
/* webserver-mini having all content */
#define WEBSERVER_CONF_CONNS 6
#define WEBSERVER_CONF_NAMESIZE 20
#define WEBSERVER_CONF_BUFSIZE 40
@ -123,7 +142,10 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
#define WEBSERVER_CONF_LOG 1
/* Include referrer in log */
#define WEBSERVER_CONF_REFERER 1
#endif
#else
#error Specified WEBSERVER_CONF_NANO configuration not supported.
#endif /* WEBSERVER_CONF_NANO */
/* Address printing used by cgi's and logging, but it can be turned off if desired */
#if WEBSERVER_CONF_LOG || WEBSERVER_CONF_ADDRESSES || WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES

View File

@ -35,9 +35,7 @@
#include <stdio.h>
#include "contiki.h"
#include "sys/log.h"
//#include "http-strings.h"
#include "webserver-nogui.h"
#include "httpd.h"
@ -59,11 +57,11 @@ PROCESS_THREAD(webserver_nogui_process, ev, data)
PROCESS_END();
}
#if WEBSERVER_CONF_LOG
/*---------------------------------------------------------------------------*/
void
webserver_log_file(uip_ipaddr_t *requester, char *file)
{
#if LOG_CONF_ENABLED
/* Print out IP address of requesting host. */
#if UIP_CONF_IPV6
@ -81,14 +79,14 @@ webserver_log_file(uip_ipaddr_t *requester, char *file)
sprintf(buf, "%d.%d.%d.%d: ", requester->u8[0], requester->u8[1],
requester->u8[2], requester->u8[3]);
#endif /* UIP_CONF_IPV6 */
log_message(buf, file);
#endif /* LOG_CONF_ENABLED */
//log_message(buf, file);
printf("%s%s\n", buf, file);
}
/*---------------------------------------------------------------------------*/
void
webserver_log(char *msg)
{
log_message(msg, "");
//log_message(msg, "");
printf("%s\n", msg);
}
/*---------------------------------------------------------------------------*/
#endif /* WEBSERVER_CONF_LOG */