Add static coffee file system to webserver
This commit is contained in:
parent
c1b7375a5a
commit
928bbc206a
9 changed files with 442 additions and 222 deletions
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd-cgi.c,v 1.2 2009/06/19 17:11:28 dak664 Exp $
|
||||
* $Id: httpd-cgi.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -50,11 +50,18 @@
|
|||
#include "httpd-cgi.h"
|
||||
#include "httpd-fs.h"
|
||||
#include "httpd-fsdata.h"
|
||||
|
||||
//#include "lib/petsciiconv.h"
|
||||
#define petsciiconv_toascii(...)
|
||||
|
||||
#include "sensors.h"
|
||||
|
||||
#define DEBUGLOGIC 0 //see httpd.c
|
||||
#if DEBUGLOGIC
|
||||
#define uip_mss(...) 512
|
||||
#define uip_appdata TCPBUF
|
||||
extern char TCPBUF[512];
|
||||
#endif
|
||||
|
||||
static struct httpd_cgi_call *calls = NULL;
|
||||
|
||||
/*cgi function names*/
|
||||
|
@ -133,25 +140,30 @@ generate_file_stats(void *arg)
|
|||
{
|
||||
char tmp[20];
|
||||
struct httpd_fsdata_file_noconst *f,fram;
|
||||
u16_t i,numprinted;
|
||||
u16_t i;
|
||||
unsigned short numprinted;
|
||||
|
||||
/* Transfer arg from flash file to RAM */
|
||||
memcpy_P_trim(tmp, (char *)arg);
|
||||
/* Transfer arg from whichever flash that contains the html file to RAM */
|
||||
httpd_fs_cpy(&tmp, (char *)arg, 20);
|
||||
|
||||
/* Count for this page, with common page footer */
|
||||
if (tmp[0]=='.') {
|
||||
return snprintf_P((char *)uip_appdata, uip_mss(),
|
||||
numprinted=snprintf_P((char *)uip_appdata, uip_mss(),
|
||||
PSTR("<p class=right><br><br><i>This page has been sent %u times</i></div></body></html>"), httpd_fs_open(thisfilename, 0));
|
||||
|
||||
/* Count for all files */
|
||||
/* Note buffer will overflow if there are too many files! */
|
||||
} else if (tmp[0]=='*') {
|
||||
i=0;numprinted=0;
|
||||
for(f = (struct httpd_fsdata_file_noconst *)httpd_get_root();
|
||||
for(f = (struct httpd_fsdata_file_noconst *)httpd_fs_get_root();
|
||||
f != NULL;
|
||||
f = (struct httpd_fsdata_file_noconst *)fram.next) {
|
||||
|
||||
/* Get the linked list file entry into RAM from program flash memory*/
|
||||
memcpy_P(&fram,f,sizeof(fram));
|
||||
memcpy_P(&tmp,fram.name,sizeof(tmp));
|
||||
|
||||
/* Get the file name from whatever flash memory it is in */
|
||||
httpd_fs_cpy(&tmp, fram.name, sizeof(tmp));
|
||||
numprinted+=snprintf_P((char *)uip_appdata + numprinted, uip_mss() - numprinted,
|
||||
#if HTTPD_FS_STATISTICS==1
|
||||
PSTR("<tr><td><a href=\"%s\">%s</a></td><td>%d</td>"),tmp,tmp,f->count);
|
||||
|
@ -159,12 +171,15 @@ generate_file_stats(void *arg)
|
|||
PSTR("<tr><td><a href=\"%s\">%s</a></td><td>%d</td>"),tmp,tmp,httpd_filecount[i++]);
|
||||
#endif
|
||||
}
|
||||
return numprinted;
|
||||
|
||||
/* Count for specified file */
|
||||
} else {
|
||||
return snprintf_P((char *)uip_appdata, uip_mss(), PSTR("%5u"), httpd_fs_open(tmp, 0));
|
||||
numprinted=snprintf_P((char *)uip_appdata, uip_mss(), PSTR("%5u"), httpd_fs_open(tmp, 0));
|
||||
}
|
||||
#if DEBUGLOGIC
|
||||
return 0;
|
||||
#endif
|
||||
return numprinted;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
|
@ -174,7 +189,8 @@ 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 *) (strchr_P(ptr, ' ') + 1));
|
||||
|
||||
PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) ptr);
|
||||
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
|
@ -229,7 +245,7 @@ make_processes(void *p)
|
|||
char name[40],tstate[20];
|
||||
|
||||
strncpy(name, ((struct process *)p)->name, 40);
|
||||
//petsciiconv_toascii(name, 40);
|
||||
petsciiconv_toascii(name, 40);
|
||||
strcpy_P(tstate,states[9 + ((struct process *)p)->state]);
|
||||
return snprintf_P((char *)uip_appdata, uip_mss(),
|
||||
PSTR("<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n"),
|
||||
|
|
|
@ -30,14 +30,13 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-fs.c,v 1.2 2009/06/19 17:11:28 dak664 Exp $
|
||||
* $Id: httpd-fs.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
|
||||
*/
|
||||
|
||||
#include "contiki-net.h"
|
||||
#include "httpd.h"
|
||||
#include "httpd-fs.h"
|
||||
#include "httpd-fsdata.h"
|
||||
|
||||
#include "httpd-fsdata.c"
|
||||
|
||||
#if HTTPD_FS_STATISTICS==2
|
||||
|
@ -46,11 +45,18 @@ u16_t httpd_filecount[HTTPD_FS_NUMFILES];
|
|||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void *
|
||||
httpd_get_root()
|
||||
httpd_fs_get_root()
|
||||
{
|
||||
return (void *)HTTPD_FS_ROOT;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
u16_t
|
||||
httpd_fs_get_size()
|
||||
{
|
||||
return HTTPD_FS_SIZE;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
u16_t
|
||||
httpd_fs_open(const char *name, struct httpd_fs_file *file)
|
||||
{
|
||||
|
@ -62,24 +68,28 @@ httpd_fs_open(const char *name, struct httpd_fs_file *file)
|
|||
for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
|
||||
f != NULL;
|
||||
f = (struct httpd_fsdata_file_noconst *)fram.next) {
|
||||
|
||||
/*Get the linked list entry into ram from program flash */
|
||||
memcpy_P(&fram,f,sizeof(fram));
|
||||
if(strcmp_P(name, fram.name) == 0) {
|
||||
|
||||
/*Compare name passed in RAM with name in whatever flash the file is in */
|
||||
if(httpd_fs_strcmp((char *)name, fram.name) == 0) {
|
||||
if (file) {
|
||||
file->data = fram.data;
|
||||
file->len = fram.len;
|
||||
#if HTTPD_FS_STATISTICS==1
|
||||
#if HTTPD_FS_STATISTICS==1 //increment count in linked list field if it is in RAM
|
||||
f->count++;
|
||||
}
|
||||
return f->count;
|
||||
}
|
||||
++i
|
||||
#elif HTTPD_FS_STATISTICS==2
|
||||
#elif HTTPD_FS_STATISTICS==2 //increment count in RAM array when linked list is in flash
|
||||
++httpd_filecount[i];
|
||||
}
|
||||
return httpd_filecount[i];
|
||||
}
|
||||
++i;
|
||||
#else
|
||||
#else //no file statistics
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-fs.h,v 1.2 2009/06/19 17:11:28 dak664 Exp $
|
||||
* $Id: httpd-fs.h,v 1.3 2009/07/23 16:16:07 dak664 Exp $
|
||||
*/
|
||||
#ifndef __HTTPD_FS_H__
|
||||
#define __HTTPD_FS_H__
|
||||
|
@ -45,23 +45,43 @@ extern u16_t httpd_filecount[];
|
|||
#endif /* HTTPD_FS_STATISTICS */
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#if COFFEE_FILES
|
||||
#include "cfs-coffee-arch.h"
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
struct httpd_fs_file {
|
||||
char *data;
|
||||
int len;
|
||||
};
|
||||
|
||||
/* file must be allocated by caller and will be filled in
|
||||
by the function. If NULL, just file stats are returned.*/
|
||||
/* Initialize the file system and set statistics to zero */
|
||||
void httpd_fs_init(void);
|
||||
/* Returns root of http files in program flash */
|
||||
void* httpd_fs_get_root();
|
||||
/* Returns size of http files in any flash */
|
||||
u16_t httpd_fs_get_size();
|
||||
/* Open a file in any flash and return statistics if enabled.
|
||||
If file is allocated by caller it will be filled in.
|
||||
If NULL, just file stats are returned.
|
||||
*/
|
||||
u16_t httpd_fs_open(const char *name, struct httpd_fs_file *file);
|
||||
|
||||
/* Returns root of http pages in flash */
|
||||
void * httpd_get_root();
|
||||
#if COFFEE_FILES
|
||||
/* Coffee file system can be static or dynamic. If static, new files
|
||||
can not be created and rewrites of an existing file can not be
|
||||
made beyond the initial allocation.
|
||||
*/
|
||||
#define httpd_fs_cpy avr_httpd_fs_cpy
|
||||
#define httpd_fs_getchar avr_httpd_fs_getchar
|
||||
#define httpd_fs_strcmp avr_httpd_fs_strcmp
|
||||
#define httpd_fs_strchr avr_httpd_fs_strchr
|
||||
|
||||
void httpd_fs_init(void);
|
||||
|
||||
#define httpd_fs_cpy memcpy_P
|
||||
#define httpd_fs_strchr strchr_P
|
||||
#define httpd_fs_getchar(x) pgm_read_byte(x)
|
||||
#else
|
||||
/* These will fail if the web content is above 64K in program flash */
|
||||
#define httpd_fs_cpy memcpy_P
|
||||
#define httpd_fs_strcmp strcmp_P
|
||||
#define httpd_fs_strchr strchr_P
|
||||
#define httpd_fs_getchar(x) pgm_read_byte(x)
|
||||
#endif
|
||||
|
||||
#endif /* __HTTPD_FS_H__ */
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd.c,v 1.2 2009/06/19 17:11:28 dak664 Exp $
|
||||
* $Id: httpd.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -40,14 +40,43 @@
|
|||
#include "webserver.h"
|
||||
#include "httpd-fs.h"
|
||||
#include "httpd-cgi.h"
|
||||
//#include "lib/petsciiconv.h"
|
||||
//#include "http-strings.h"
|
||||
|
||||
#include "httpd.h"
|
||||
//#include "lib/petsciiconv.h"
|
||||
#define petsciiconv_topetscii(...)
|
||||
//#include "http-strings.h"
|
||||
#if COFFEE_FILES
|
||||
#include "cfs-coffee-arch.h"
|
||||
#endif /* COFFEE_FILES */
|
||||
|
||||
/* DEBUGLOGIC is a convenient way to debug in a simulator without a tcp/ip connection.
|
||||
* Break the program in the process loop and step from the entry in httpd_appcall.
|
||||
* The input file is forced to /index.html and the output directed to TCPBUF.
|
||||
* If cgi's are invoked define it in httpd-cgi.c as well.
|
||||
* psock_generator_send in /core/net/psock.c must also be modified as follows:
|
||||
* ...
|
||||
* // Wait until all data is sent and acknowledged.
|
||||
* if (!s->sendlen) break; //<---add this line
|
||||
* PT_YIELD_UNTIL(&s->psockpt, uip_acked() || uip_rexmit());
|
||||
* ...
|
||||
*/
|
||||
#define DEBUGLOGIC 0
|
||||
#define DEBUG 0
|
||||
#if DEBUGLOGIC
|
||||
struct httpd_state *sg;
|
||||
#define uip_mss(...) 512
|
||||
#define uip_appdata TCPBUF
|
||||
char TCPBUF[512];
|
||||
#endif
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#ifndef WEBSERVER_CONF_CGI_CONNS
|
||||
#define CONNS 4
|
||||
#else /* WEBSERVER_CONF_CGI_CONNS */
|
||||
#else
|
||||
#define CONNS WEBSERVER_CONF_CGI_CONNS
|
||||
#endif /* WEBSERVER_CONF_CGI_CONNS */
|
||||
|
||||
|
@ -57,6 +86,8 @@
|
|||
//#define SEND_STRING(s, str) PSOCK_SEND(s, (uint8_t *)str, (unsigned int)strlen(str))
|
||||
MEMB(conns, struct httpd_state, CONNS);
|
||||
|
||||
/* MAX_SCRIPT_NAME_LENGTH should be at least be the maximum file name length+2 for %!: includes */
|
||||
#define MAX_SCRIPT_NAME_LENGTH 20
|
||||
#define ISO_tab 0x09
|
||||
#define ISO_nl 0x0a
|
||||
#define ISO_cr 0x0d
|
||||
|
@ -78,10 +109,12 @@ generate(void *state)
|
|||
} else {
|
||||
s->len = s->file.len;
|
||||
}
|
||||
|
||||
httpd_fs_cpy(uip_appdata, s->file.data, s->len);
|
||||
|
||||
#if DEBUGLOGIC
|
||||
return 0;
|
||||
#else
|
||||
return s->len;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
|
@ -89,12 +122,12 @@ PT_THREAD(send_file(struct httpd_state *s))
|
|||
{
|
||||
PSOCK_BEGIN(&s->sout);
|
||||
|
||||
do {
|
||||
do {
|
||||
PSOCK_GENERATOR_SEND(&s->sout, generate, s);
|
||||
s->file.len -= s->len;
|
||||
s->file.len -= s->len;
|
||||
s->file.data += s->len;
|
||||
} while(s->file.len > 0);
|
||||
|
||||
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -102,15 +135,15 @@ static
|
|||
PT_THREAD(send_part_of_file(struct httpd_state *s))
|
||||
{
|
||||
PSOCK_BEGIN(&s->sout);
|
||||
|
||||
|
||||
static int oldfilelen, oldlen;
|
||||
static char * olddata;
|
||||
|
||||
|
||||
//Store stuff that gets clobbered...
|
||||
oldfilelen = s->file.len;
|
||||
oldlen = s->len;
|
||||
olddata = s->file.data;
|
||||
|
||||
|
||||
//How much to send
|
||||
s->file.len = s->len;
|
||||
|
||||
|
@ -119,7 +152,7 @@ PT_THREAD(send_part_of_file(struct httpd_state *s))
|
|||
s->file.len -= s->len;
|
||||
s->file.data += s->len;
|
||||
} while(s->file.len > 0);
|
||||
|
||||
|
||||
s->len = oldlen;
|
||||
s->file.len = oldfilelen;
|
||||
s->file.data = olddata;
|
||||
|
@ -131,11 +164,11 @@ static void
|
|||
next_scriptstate(struct httpd_state *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
/* Skip over any script parameters to the beginning of the next line */
|
||||
if((p = (char *)httpd_fs_strchr(s->scriptptr, ISO_nl)) != NULL) {
|
||||
p += 1;
|
||||
s->scriptlen -= (unsigned short)(p - s->scriptptr);
|
||||
s->scriptptr = p;
|
||||
s->scriptptr = p;
|
||||
} else {
|
||||
s->scriptlen = 0;
|
||||
}
|
||||
|
@ -147,58 +180,67 @@ next_scriptstate(struct httpd_state *s)
|
|||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
memcpy_P_trim(char *toram, char *fromflash)
|
||||
char *
|
||||
get_scriptname(char *dest, char *fromfile)
|
||||
{
|
||||
uint8_t i;
|
||||
for (i=0;i<19;) {
|
||||
toram[i]=pgm_read_byte_near(fromflash++);
|
||||
if (toram[i]==ISO_tab) {if (i) break; else continue;} //skip leading tabs
|
||||
if (toram[i]==ISO_space) {if (i) break; else continue;} //skip leading spaces
|
||||
if (toram[i]==ISO_nl) break; //nl is preferred delimiter
|
||||
if (toram[i]==ISO_cr) break; //some editors insert cr
|
||||
if (toram[i]==0) break; //files are terminated with null
|
||||
uint8_t i=0,skip=1;
|
||||
/* Extract a file or cgi name, trim leading spaces and replace termination with zero */
|
||||
/* Returns number of characters processed up to the next non-tab or space */
|
||||
do {
|
||||
dest[i]=httpd_fs_getchar(fromfile++);
|
||||
if (dest[i]==ISO_colon) {if (!skip) break;} //allow leading colons
|
||||
else if (dest[i]==ISO_tab ) {if (skip) continue;else break;}//skip leading tabs
|
||||
else if (dest[i]==ISO_space) {if (skip) continue;else break;}//skip leading spaces
|
||||
else if (dest[i]==ISO_nl ) break; //nl is preferred delimiter
|
||||
else if (dest[i]==ISO_cr ) break; //some editors insert cr
|
||||
else if (dest[i]==0 ) break; //files are terminated with null
|
||||
else skip=0;
|
||||
i++;
|
||||
}
|
||||
toram[i]=0;
|
||||
|
||||
}
|
||||
} while (i<(MAX_SCRIPT_NAME_LENGTH+1));
|
||||
fromfile--;
|
||||
while ((dest[i]==ISO_space) || (dest[i]==ISO_tab)) dest[i]=httpd_fs_getchar(++fromfile);
|
||||
dest[i]=0;
|
||||
return (fromfile);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char filenamebuf[25],*pptr;//See below!
|
||||
|
||||
static
|
||||
PT_THREAD(handle_script(struct httpd_state *s))
|
||||
{
|
||||
// char *ptr; //one of these gets whomped unless in globals
|
||||
// char filenamebuf[25];
|
||||
|
||||
/* Note script includes will attach a leading : to the filename and a trailing zero */
|
||||
static char scriptname[MAX_SCRIPT_NAME_LENGTH+1],*pptr;
|
||||
static uint16_t filelength;
|
||||
|
||||
PT_BEGIN(&s->scriptpt);
|
||||
|
||||
filelength=s->file.len;
|
||||
while(s->file.len > 0) {
|
||||
/* Sanity check */
|
||||
if (s->file.len > filelength) break;
|
||||
|
||||
/* Check if we should start executing a script. */
|
||||
/* Check if we should start executing a script, flagged by %! */
|
||||
if(httpd_fs_getchar(s->file.data) == ISO_percent &&
|
||||
httpd_fs_getchar(s->file.data + 1) == ISO_bang) {
|
||||
s->scriptptr = s->file.data + 3;
|
||||
s->scriptlen = s->file.len - 3;
|
||||
memcpy_P_trim(filenamebuf,s->scriptptr);
|
||||
|
||||
if(httpd_fs_getchar(s->scriptptr - 1) == ISO_colon) {
|
||||
httpd_fs_open(filenamebuf, &s->file);
|
||||
PT_WAIT_THREAD(&s->scriptpt, send_file(s));
|
||||
} else {
|
||||
PT_WAIT_THREAD(&s->scriptpt,
|
||||
httpd_cgi(filenamebuf)(s, s->scriptptr));
|
||||
}
|
||||
next_scriptstate(s);
|
||||
/* Extract name, if starts with colon include file else call cgi */
|
||||
s->scriptptr=get_scriptname(scriptname,s->file.data+2);
|
||||
s->scriptlen=s->file.len-(s->scriptptr-s->file.data);
|
||||
PRINTF("httpd: Handle script named %s\n",scriptname);
|
||||
if(scriptname[0] == ISO_colon) {
|
||||
if (httpd_fs_open(&scriptname[1], &s->file)) {
|
||||
PT_WAIT_THREAD(&s->scriptpt, send_file(s));
|
||||
}
|
||||
} else {
|
||||
PT_WAIT_THREAD(&s->scriptpt,httpd_cgi(scriptname)(s, s->scriptptr));
|
||||
}
|
||||
next_scriptstate(s);
|
||||
|
||||
/* The script is over, so we reset the pointers and continue
|
||||
sending the rest of the file. */
|
||||
/* Reset the pointers and continue sending the current file. */
|
||||
s->file.data = s->scriptptr;
|
||||
s->file.len = s->scriptlen;
|
||||
s->file.len = s->scriptlen;
|
||||
} else {
|
||||
/* See if we find the start of script marker in the block of HTML
|
||||
to be sent. */
|
||||
|
||||
/* Send file up to the next potential script */
|
||||
if(s->file.len > uip_mss()) {
|
||||
s->len = uip_mss();
|
||||
} else {
|
||||
|
@ -210,15 +252,17 @@ PT_THREAD(handle_script(struct httpd_state *s))
|
|||
} else {
|
||||
pptr = (char *) httpd_fs_strchr(s->file.data, ISO_percent);
|
||||
}
|
||||
|
||||
if(pptr != NULL && pptr != s->file.data) {
|
||||
s->len = (int)(pptr - s->file.data);
|
||||
if(s->len >= uip_mss()) {
|
||||
s->len = uip_mss();
|
||||
}
|
||||
}
|
||||
PRINTF("httpd: Sending %u bytes from 0x%04x\n",s->file.len,s->file.data);
|
||||
PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));
|
||||
s->file.data += s->len;
|
||||
s->file.len -= s->len;
|
||||
s->file.len -= s->len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,7 +277,11 @@ generate_status_P(void *pstr)
|
|||
memcpy_P(uip_appdata+9, pstr, slen);
|
||||
slen+=9;
|
||||
memcpy_P(uip_appdata+slen, PSTR("\r\nServer: Contiki/2.0 http://www.sics.se/contiki/\r\nConnection: close\r\n"), 70);
|
||||
#if DEBUGLOGIC
|
||||
return 0;
|
||||
#else
|
||||
return slen+70;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
|
@ -244,7 +292,11 @@ generate_header_P(void *pstr)
|
|||
memcpy_P(uip_appdata+14, pstr, slen);
|
||||
slen+=14;
|
||||
memcpy_P(uip_appdata+slen,PSTR("\r\n\r\n"),4);
|
||||
#if DEBUGLOGIC
|
||||
return 0;
|
||||
#else
|
||||
return slen+4;
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
@ -296,7 +348,9 @@ PT_THREAD(handle_output(struct httpd_state *s))
|
|||
char *ptr;
|
||||
|
||||
PT_BEGIN(&s->outputpt);
|
||||
// strcpy(s->filename,"/index.html"); //for debugging
|
||||
#if DEBUGLOGIC
|
||||
strcpy(s->filename,"/index.html");
|
||||
#endif
|
||||
if(!httpd_fs_open(s->filename, &s->file)) {
|
||||
strcpy_P(s->filename, PSTR("/404.html"));
|
||||
httpd_fs_open(s->filename, &s->file);
|
||||
|
@ -320,7 +374,8 @@ char http_get[4] PROGMEM ="GET ";
|
|||
char http_ref[8] PROGMEM ="Referer:";
|
||||
static
|
||||
PT_THREAD(handle_input(struct httpd_state *s))
|
||||
{
|
||||
{
|
||||
|
||||
PSOCK_BEGIN(&s->sin);
|
||||
|
||||
PSOCK_READTO(&s->sin, ISO_space);
|
||||
|
@ -350,7 +405,7 @@ PT_THREAD(handle_input(struct httpd_state *s))
|
|||
|
||||
if(strncmp_P(s->inputbuf, http_ref, 8) == 0) {
|
||||
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
|
||||
// petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
|
||||
petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
|
||||
webserver_log(s->inputbuf);
|
||||
}
|
||||
}
|
||||
|
@ -360,17 +415,25 @@ PT_THREAD(handle_input(struct httpd_state *s))
|
|||
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
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
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;
|
||||
|
||||
if(uip_closed() || uip_aborted() || uip_timedout()) {
|
||||
if(s != NULL) {
|
||||
memb_free(&conns, s);
|
||||
|
@ -381,6 +444,7 @@ httpd_appcall(void *state)
|
|||
uip_abort();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
tcp_markconn(uip_conn, s);
|
||||
PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
|
||||
PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
|
||||
|
@ -393,8 +457,8 @@ httpd_appcall(void *state)
|
|||
if(uip_poll()) {
|
||||
++s->timer;
|
||||
if(s->timer >= 20) {
|
||||
uip_abort();
|
||||
memb_free(&conns, s);
|
||||
uip_abort();
|
||||
memb_free(&conns, s);
|
||||
}
|
||||
} else {
|
||||
s->timer = 0;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd.h,v 1.2 2009/06/19 17:11:28 dak664 Exp $
|
||||
* $Id: httpd.h,v 1.3 2009/07/23 16:16:07 dak664 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -59,6 +59,5 @@ struct httpd_state {
|
|||
|
||||
void httpd_init(void);
|
||||
void httpd_appcall(void *state);
|
||||
void memcpy_P_trim(char *toram, char *fromflash);
|
||||
|
||||
#endif /* __HTTPD_H__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue