Fix avr progmem string accesses, add DEBUGLOGIC, configure sky defaults

This commit is contained in:
David Kopf 2011-07-25 15:08:49 -04:00
parent 0e59a0360e
commit e3368ffb67
4 changed files with 95 additions and 33 deletions

View file

@ -58,27 +58,6 @@ httpd_fs_get_size()
return HTTPD_FS_SIZE; return HTTPD_FS_SIZE;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
static u8_t
httpd_fs_strcmp(const char *str1, const char *str2)
{
u8_t i;
i = 0;
loop:
if(str2[i] == 0 ||
str1[i] == '\r' ||
str1[i] == '\n') {
return 0;
}
if(str1[i] != str2[i]) {
return 1;
}
++i;
goto loop;
}
/*-----------------------------------------------------------------------------------*/
uint16_t uint16_t
httpd_fs_open(const char *name, struct httpd_fs_file *file) httpd_fs_open(const char *name, struct httpd_fs_file *file)
{ {

View file

@ -355,6 +355,9 @@ PT_THREAD(handle_output(struct httpd_state *s))
char *ptr; char *ptr;
PT_BEGIN(&s->outputpt); PT_BEGIN(&s->outputpt);
#if DEBUGLOGIC
httpd_strcpy(s->filename,httpd_indexfn);
#endif
if(!httpd_fs_open(s->filename, &s->file)) { if(!httpd_fs_open(s->filename, &s->file)) {
#if WEBSERVER_CONF_INCLUDE || WEBSERVER_CONF_CGI #if WEBSERVER_CONF_INCLUDE || WEBSERVER_CONF_CGI
/* If index.html not found try index.shtml */ /* If index.html not found try index.shtml */
@ -410,22 +413,22 @@ PT_THREAD(handle_input(struct httpd_state *s))
if(s->inputbuf[1] == ISO_space) { if(s->inputbuf[1] == ISO_space) {
httpd_strcpy(s->filename, httpd_indexfn); httpd_strcpy(s->filename, httpd_indexfn);
} else { } else {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; uint8_t i;
strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
#if WEBSERVER_CONF_PASSQUERY
/* Query string is left in the buffer until zeroed by the application! */
{uint8_t i;
for (i=0;i<sizeof(s->filename)+1;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 (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) { if (s->inputbuf[i]==ISO_qmark) {
s->inputbuf[i]=0;
strncpy(httpd_query,&s->inputbuf[i+1],sizeof(httpd_query)); strncpy(httpd_query,&s->inputbuf[i+1],sizeof(httpd_query));
// raven_lcd_show_text(&s->inputbuf[i]); break;
} }
}
}
#endif #endif
s->filename[i]=s->inputbuf[i];
}
s->filename[i]=0;
} }
#if WEBSERVER_CONF_LOG #if WEBSERVER_CONF_LOG
webserver_log_file(&uip_conn->ripaddr, s->filename); webserver_log_file(&uip_conn->ripaddr, s->filename);
// webserver_log(httpd_query); // webserver_log(httpd_query);
@ -447,6 +450,9 @@ PT_THREAD(handle_input(struct httpd_state *s))
static void static void
handle_connection(struct httpd_state *s) handle_connection(struct httpd_state *s)
{ {
#if DEBUGLOGIC
handle_output(s);
#endif
handle_input(s); handle_input(s);
if(s->state == STATE_OUTPUT) { if(s->state == STATE_OUTPUT) {
handle_output(s); handle_output(s);
@ -456,6 +462,11 @@ handle_connection(struct httpd_state *s)
void void
httpd_appcall(void *state) httpd_appcall(void *state)
{ {
#if DEBUGLOGIC
struct httpd_state *s; //Enter here for debugging with output directed to TCPBUF
s = sg = (struct httpd_state *)memb_alloc(&conns);
if (1) {
#else
struct httpd_state *s = (struct httpd_state *)state; struct httpd_state *s = (struct httpd_state *)state;
if(uip_closed() || uip_aborted() || uip_timedout()) { if(uip_closed() || uip_aborted() || uip_timedout()) {
if(s != NULL) { if(s != NULL) {
@ -467,6 +478,7 @@ httpd_appcall(void *state)
uip_abort(); uip_abort();
return; return;
} }
#endif
tcp_markconn(uip_conn, s); tcp_markconn(uip_conn, s);
PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1); PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);

View file

@ -44,6 +44,7 @@
* The RAM needed for each entry depends on script enabling and buffer sizes; see struct httpd_state below. * 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 * Typical range is 100 - 200 bytes per connection
*/ */
#if CONTIKI_TARGET_SKY
#define WEBSERVER_CONF_CONNS 2 #define WEBSERVER_CONF_CONNS 2
#define WEBSERVER_CONF_NAMESIZE 16 #define WEBSERVER_CONF_NAMESIZE 16
#define WEBSERVER_CONF_BUFSIZE 40 #define WEBSERVER_CONF_BUFSIZE 40
@ -83,6 +84,47 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
/* Include referrer in log */ /* Include referrer in log */
#define WEBSERVER_CONF_REFERER 0 #define WEBSERVER_CONF_REFERER 0
#else /* !sky */
#define WEBSERVER_CONF_CONNS 6
#define WEBSERVER_CONF_NAMESIZE 20
#define WEBSERVER_CONF_BUFSIZE 40
/* Allow include in .shtml pages, e.g. %!: /header.html */
#define WEBSERVER_CONF_INCLUDE 1
/* Allow cgi in .shtml pages, e.g. %! file-stats . */
#define WEBSERVER_CONF_CGI 1
/* MAX_SCRIPT_NAME_LENGTH should be at least the maximum file name length+2 for %!: includes */
#define MAX_SCRIPT_NAME_LENGTH WEBSERVER_CONF_NAMESIZE+2
/* Enable specific cgi's */
#define WEBSERVER_CONF_HEADER 1
//#define WEBSERVER_CONF_HEADER_W3C 1 //Proper header
#define WEBSERVER_CONF_HEADER_MENU 1 //with links to other pages
//#define WEBSERVER_CONF_HEADER_ICON 1 //with favicon
#define WEBSERVER_CONF_FILESTATS 1
#define WEBSERVER_CONF_TCPSTATS 1
#define WEBSERVER_CONF_PROCESSES 1
#define WEBSERVER_CONF_ADDRESSES 1
#define WEBSERVER_CONF_NEIGHBORS 1
#define WEBSERVER_CONF_ROUTES 1
#define WEBSERVER_CONF_SENSORS 1
#define WEBSERVER_CONF_TICTACTOE 1 //Needs passquery of at least 10 chars
#define WEBSERVER_CONF_PASSQUERY 10
#if WEBSERVER_CONF_PASSQUERY
extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
#endif
/* Enable specific file types */
#define WEBSERVER_CONF_JPG 1
#define WEBSERVER_CONF_PNG 1
#define WEBSERVER_CONF_GIF 1
#define WEBSERVER_CONF_TXT 1
#define WEBSERVER_CONF_CSS 1
#define WEBSERVER_CONF_BIN 1
/* Log page accesses */
#define WEBSERVER_CONF_LOG 1
/* Include referrer in log */
#define WEBSERVER_CONF_REFERER 1
#endif
/* Address printing used by cgi's and logging, but it can be turned off if desired */ /* 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 #if WEBSERVER_CONF_LOG || WEBSERVER_CONF_ADDRESSES || WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES
#define WEBSERVER_CONF_PRINTADDR 1 #define WEBSERVER_CONF_PRINTADDR 1
@ -108,6 +150,7 @@ uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result);
#define httpd_strlen strlen_P #define httpd_strlen strlen_P
#define httpd_snprintf snprintf_P #define httpd_snprintf snprintf_P
#define httpd_fs_cpy memcpy_P #define httpd_fs_cpy memcpy_P
#define httpd_fs_strcmp strcmp_P
#define httpd_fs_strchr strchr_P #define httpd_fs_strchr strchr_P
#define httpd_fs_getchar(x) pgm_read_byte(x) #define httpd_fs_getchar(x) pgm_read_byte(x)
@ -122,6 +165,7 @@ uint8_t httpd_cgi_sprint_ip6(uip_ip6addr_t addr, char * result);
#define httpd_strncmp strncmp #define httpd_strncmp strncmp
#define httpd_strlen strlen #define httpd_strlen strlen
#define httpd_fs_strchr strchr #define httpd_fs_strchr strchr
#define httpd_fs_strcmp strcmp
#define httpd_fs_getchar(c) *(c) #define httpd_fs_getchar(c) *(c)
#endif #endif
@ -152,4 +196,27 @@ struct httpd_state {
void httpd_init(void); void httpd_init(void);
void httpd_appcall(void *state); void httpd_appcall(void *state);
/* DEBUGLOGIC is a convenient way to debug without a tcp/ip connection.
* After initialization, break the program and set the program counter
* to the beginning of httpd.c::httpd_appcall:
* s = sg = (struct httpd_state *)memb_alloc(&conns);
* The global sg points to the s data to get around "not in scope" optimization.
* The input file is forced to /index.html and the output directed to TCPBUF.
* However the socket will hang on acknowledgement when any data is sent.
* To prevent this just add a break to /core/net/psock.c::psock_generator_send
* ...
* // Wait until all data is sent and acknowledged.
* break; //<---add this line
* PT_YIELD_UNTIL(&s->psockpt, uip_acked() || uip_rexmit());
* ...
*/
#define DEBUGLOGIC 0
#if DEBUGLOGIC
struct httpd_state *sg;
#define uip_mss(...) 512
#define uip_appdata TCPBUF
char TCPBUF[512];
#endif
#endif /* __HTTPD_H__ */ #endif /* __HTTPD_H__ */

View file

@ -26,5 +26,9 @@ code as follows:
The default webserver and content is in /apps/webserver/... The default webserver and content is in /apps/webserver/...
Change that using e.g. Change that using e.g.
$make clean
$make WITH_WEBSERVER=webserver-nano $make WITH_WEBSERVER=webserver-nano
$make TARGET=redbee-econotag WITH_WEBSERVER=webserver-nano
$make TARGET=avr-raven WITH_WEBSERVER=raven-webserver $make TARGET=avr-raven WITH_WEBSERVER=raven-webserver
******** Make clean when switching webservers! **********