Add httpd_s* function layer and HTTPD_STRING_ATTR for strings in different memory types

This commit is contained in:
dak664 2009-07-24 15:41:52 +00:00
parent ed9d31ef7c
commit 8ea4b747d0
4 changed files with 152 additions and 110 deletions

View File

@ -28,7 +28,7 @@
*
* This file is part of the uIP TCP/IP stack.
*
* $Id: httpd-cgi.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
* $Id: httpd-cgi.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $
*
*/
@ -50,12 +50,11 @@
#include "httpd-cgi.h"
#include "httpd-fs.h"
#include "httpd-fsdata.h"
//#include "lib/petsciiconv.h"
#define petsciiconv_toascii(...)
#include "lib/petsciiconv.h"
#include "sensors.h"
#define DEBUGLOGIC 0 //see httpd.c
#define DEBUGLOGIC 0 //See httpd.c, if 1 must also set it there!
#if DEBUGLOGIC
#define uip_mss(...) 512
#define uip_appdata TCPBUF
@ -66,25 +65,25 @@ static struct httpd_cgi_call *calls = NULL;
/*cgi function names*/
#if HTTPD_FS_STATISTICS
static const char file_name[] PROGMEM = "file-stats";
static const char file_name[] HTTPD_STRING_ATTR = "file-stats";
#endif
static const char tcp_name[] PROGMEM = "tcp-connections";
static const char proc_name[] PROGMEM = "processes";
static const char sensor_name[] PROGMEM = "sensors";
static const char tcp_name[] HTTPD_STRING_ATTR = "tcp-connections";
static const char proc_name[] HTTPD_STRING_ATTR = "processes";
static const char sensor_name[] HTTPD_STRING_ATTR = "sensors";
/*Process states for processes cgi*/
static const char closed[] PROGMEM = "CLOSED";
static const char syn_rcvd[] PROGMEM = "SYN-RCVD";
static const char syn_sent[] PROGMEM = "SYN-SENT";
static const char established[] PROGMEM = "ESTABLISHED";
static const char fin_wait_1[] PROGMEM = "FIN-WAIT-1";
static const char fin_wait_2[] PROGMEM = "FIN-WAIT-2";
static const char closing[] PROGMEM = "CLOSING";
static const char time_wait[] PROGMEM = "TIME-WAIT";
static const char last_ack[] PROGMEM = "LAST-ACK";
static const char none[] PROGMEM = "NONE";
static const char running[] PROGMEM = "RUNNING";
static const char called[] PROGMEM = "CALLED";
static const char closed[] HTTPD_STRING_ATTR = "CLOSED";
static const char syn_rcvd[] HTTPD_STRING_ATTR = "SYN-RCVD";
static const char syn_sent[] HTTPD_STRING_ATTR = "SYN-SENT";
static const char established[] HTTPD_STRING_ATTR = "ESTABLISHED";
static const char fin_wait_1[] HTTPD_STRING_ATTR = "FIN-WAIT-1";
static const char fin_wait_2[] HTTPD_STRING_ATTR = "FIN-WAIT-2";
static const char closing[] HTTPD_STRING_ATTR = "CLOSING";
static const char time_wait[] HTTPD_STRING_ATTR = "TIME-WAIT";
static const char last_ack[] HTTPD_STRING_ATTR = "LAST-ACK";
static const char none[] HTTPD_STRING_ATTR = "NONE";
static const char running[] HTTPD_STRING_ATTR = "RUNNING";
static const char called[] HTTPD_STRING_ATTR = "CALLED";
static const char *states[] = {
closed,
syn_rcvd,
@ -125,7 +124,7 @@ httpd_cgi(char *name)
/* Find the matching name in the table, return the function. */
for(f = calls; f != NULL; f = f->next) {
if(strncmp_P(name, f->name, strlen_P(f->name)) == 0) {
if(httpd_strncmp(name, f->name, httpd_strlen(f->name)) == 0) {
return f->function;
}
}
@ -138,6 +137,9 @@ static char *thisfilename;
static unsigned short
generate_file_stats(void *arg)
{
static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "<p class=right><br><br><i>This page has been sent %u times</i></div></body></html>";
static const char httpd_cgi_filestat2[] HTTPD_STRING_ATTR = "<tr><td><a href=\"%s\">%s</a></td><td>%d</td>";
static const char httpd_cgi_filestat3[] HTTPD_STRING_ATTR = "%5u";
char tmp[20];
struct httpd_fsdata_file_noconst *f,fram;
u16_t i;
@ -148,8 +150,7 @@ generate_file_stats(void *arg)
/* Count for this page, with common page footer */
if (tmp[0]=='.') {
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));
numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(thisfilename, 0));
/* Count for all files */
/* Note buffer will overflow if there are too many files! */
@ -159,22 +160,22 @@ generate_file_stats(void *arg)
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));
/* Get the linked list file entry into RAM from from wherever it is*/
httpd_memcpy(&fram,f,sizeof(fram));
/* Get the file name from whatever flash memory it is in */
/* Get the file name from whatever 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);
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, f->count);
#elif HTTPD_FS_STATISTICS==2
PSTR("<tr><td><a href=\"%s\">%s</a></td><td>%d</td>"),tmp,tmp,httpd_filecount[i++]);
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, httpd_filecount[i]);
#endif
i++;
}
/* Count for specified file */
} else {
numprinted=snprintf_P((char *)uip_appdata, uip_mss(), PSTR("%5u"), httpd_fs_open(tmp, 0));
numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat3, httpd_fs_open(tmp, 0));
}
#if DEBUGLOGIC
return 0;
@ -199,6 +200,8 @@ PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
static unsigned short
make_tcp_stats(void *arg)
{
static const char httpd_cgi_tcpstat1[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%d</td><td>";
static const char httpd_cgi_tcpstat2[] HTTPD_STRING_ATTR = "-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n";
struct uip_conn *conn;
struct httpd_state *s = (struct httpd_state *)arg;
char tstate[20];
@ -206,14 +209,11 @@ make_tcp_stats(void *arg)
conn = &uip_conns[s->u.count];
numprinted = snprintf_P((char *)uip_appdata, uip_mss(),
PSTR("<tr align=\"center\"><td>%d</td><td>"),
htons(conn->lport));
numprinted = httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_tcpstat1, htons(conn->lport));
numprinted += sprint_ip6(conn->ripaddr, uip_appdata + numprinted);
strcpy_P(tstate,states[conn->tcpstateflags & UIP_TS_MASK]);
numprinted += snprintf_P((char *)uip_appdata + numprinted, uip_mss() - numprinted,
PSTR("-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n"),
httpd_strcpy(tstate,states[conn->tcpstateflags & UIP_TS_MASK]);
numprinted += httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted,
httpd_cgi_tcpstat2,
htons(conn->rport),
tstate,
conn->nrtx,
@ -242,14 +242,13 @@ PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))
static unsigned short
make_processes(void *p)
{
static const char httpd_cgi_proc[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n";
char name[40],tstate[20];
strncpy(name, ((struct process *)p)->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"),
p, name,
httpd_strcpy(tstate,states[9 + ((struct process *)p)->state]);
return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_proc, p, name,
// *((char **)&(((struct process *)p)->thread)),
*(char *)(&(((struct process *)p)->thread)),
@ -269,8 +268,10 @@ PT_THREAD(processes(struct httpd_state *s, char *ptr))
static unsigned short
generate_sensor_readings(void *arg)
{
if (!sensor_temperature[0]) return snprintf_P((char *)uip_appdata,uip_mss(),PSTR("<em>Temperature:</em> Not enabled\n"));
return snprintf_P((char *)uip_appdata, uip_mss(), PSTR("<em>Temperature:</em> %s\n"), sensor_temperature);
static const char httpd_cgi_sensor1[] HTTPD_STRING_ATTR = "<em>Temperature:</em> Not enabled\n";
static const char httpd_cgi_sensor2[] HTTPD_STRING_ATTR = "<em>Temperature:</em> %s\n";
if (!sensor_temperature[0]) return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor1);
return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_sensor2, sensor_temperature);
}
/*---------------------------------------------------------------------------*/
static
@ -299,26 +300,24 @@ httpd_cgi_add(struct httpd_cgi_call *c)
/*---------------------------------------------------------------------------*/
#if HTTPD_FS_STATISTICS
HTTPD_CGI_CALL(file, file_name, file_stats);
HTTPD_CGI_CALL( file, file_name, file_stats);
#endif
HTTPD_CGI_CALL(tcp, tcp_name, tcp_stats);
HTTPD_CGI_CALL(proc, proc_name, processes);
HTTPD_CGI_CALL( tcp, tcp_name, tcp_stats );
HTTPD_CGI_CALL( proc, proc_name, processes );
HTTPD_CGI_CALL(sensors, sensor_name, sensor_readings);
void
httpd_cgi_init(void)
{
#if HTTPD_FS_STATISTICS
httpd_cgi_add(&file);
httpd_cgi_add( &file);
#endif
httpd_cgi_add(&tcp);
httpd_cgi_add(&proc);
httpd_cgi_add( &tcp);
httpd_cgi_add( &proc);
httpd_cgi_add(&sensors);
}
/*---------------------------------------------------------------------------*/
uint8_t sprint_ip6(uip_ip6addr_t addr, char * result)
{
unsigned char zerocnt = 0;

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: httpd-fs.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
* $Id: httpd-fs.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $
*/
#include "contiki-net.h"
@ -69,8 +69,8 @@ httpd_fs_open(const char *name, struct httpd_fs_file *file)
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));
/*Get the linked list entry into ram from wherever it is */
httpd_memcpy(&fram,f,sizeof(fram));
/*Compare name passed in RAM with name in whatever flash the file is in */
if(httpd_fs_strcmp((char *)name, fram.name) == 0) {
@ -121,8 +121,8 @@ httpd_fs_count(char *name)
for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
f != NULL;
f = (struct httpd_fsdata_file_noconst *)fram.next) {
memcpy_P(&fram,f,sizeof(fram));
if(strcmp_P(name, fram.name) == 0) {
httpd_memcpy(&fram,f,sizeof(fram));
if(httpd_strcmp(name, fram.name) == 0) {
#if HTTPD_FS_STATISTICS==1
return f->count;
#elif HTTPD_FS_STATISTICS==2

View File

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: httpd.c,v 1.3 2009/07/23 16:16:07 dak664 Exp $
* $Id: httpd.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $
*/
#include <string.h>
@ -41,8 +41,7 @@
#include "httpd-fs.h"
#include "httpd-cgi.h"
#include "httpd.h"
//#include "lib/petsciiconv.h"
#define petsciiconv_topetscii(...)
//#include "http-strings.h"
#if COFFEE_FILES
#include "cfs-coffee-arch.h"
@ -51,7 +50,7 @@
/* 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.
* 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.
@ -69,8 +68,12 @@ char TCPBUF[512];
#endif
#if DEBUG
#include <stdio.h>
#if HTTPD_STRING_TYPE==PROGMEM_TYPE
#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
#else
#define PRINTF printf
#endif
#else
#define PRINTF(...)
#endif
@ -259,7 +262,7 @@ PT_THREAD(handle_script(struct httpd_state *s))
s->len = uip_mss();
}
}
PRINTF("httpd: Sending %u bytes from 0x%04x\n",s->file.len,s->file.data);
PRINTF("httpd: Sending %u bytes from 0x%04x\n",s->file.len,(unsigned int)s->file.data);
PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));
s->file.data += s->len;
s->file.len -= s->len;
@ -269,29 +272,33 @@ PT_THREAD(handle_script(struct httpd_state *s))
PT_END(&s->scriptpt);
}
/*---------------------------------------------------------------------------*/
const char httpd_http[] HTTPD_STRING_ATTR = "HTTP/1.0 ";
const char httpd_server[] HTTPD_STRING_ATTR = "\r\nServer: Contiki/2.0 http://www.sics.se/contiki/\r\nConnection: close\r\n";
static unsigned short
generate_status_P(void *pstr)
generate_status(void *sstr)
{
uint8_t slen=strlen_P(pstr);
memcpy_P(uip_appdata, PSTR("HTTP/1.0 "), 9);
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);
uint8_t slen=httpd_strlen((char *)sstr);
httpd_memcpy(uip_appdata, httpd_http, sizeof(httpd_http)-1);
httpd_memcpy(uip_appdata+sizeof(httpd_http)-1, (char *)sstr, slen);
slen+=sizeof(httpd_http)-1;
httpd_memcpy(uip_appdata+slen, httpd_server, sizeof(httpd_server)-1);
#if DEBUGLOGIC
return 0;
#else
return slen+70;
return slen+sizeof(httpd_server)-1;
#endif
}
/*---------------------------------------------------------------------------*/
const char httpd_content[] HTTPD_STRING_ATTR = "Content-type: ";
const char httpd_crlf[] HTTPD_STRING_ATTR = "\r\n\r\n";
static unsigned short
generate_header_P(void *pstr)
generate_header(void *hstr)
{
uint8_t slen=strlen_P(pstr);
memcpy_P(uip_appdata,PSTR("Content-type: "),14);
memcpy_P(uip_appdata+14, pstr, slen);
slen+=14;
memcpy_P(uip_appdata+slen,PSTR("\r\n\r\n"),4);
uint8_t slen=httpd_strlen((char *)hstr);
httpd_memcpy(uip_appdata,httpd_content,sizeof(httpd_content)-1);
httpd_memcpy(uip_appdata+sizeof(httpd_content)-1, (char *)hstr, slen);
slen+=sizeof(httpd_content)-1;
httpd_memcpy(uip_appdata+slen,httpd_crlf,sizeof(httpd_crlf)-1);
#if DEBUGLOGIC
return 0;
#else
@ -299,49 +306,54 @@ generate_header_P(void *pstr)
#endif
}
/*---------------------------------------------------------------------------*/
char http_htm[10] PROGMEM ="text/html";
char http_css[ 9] PROGMEM ="text/css";
char http_png[10] PROGMEM ="image/png";
char http_gif[10] PROGMEM ="image/gif";
char http_jpg[11] PROGMEM ="image/jpeg";
char http_txt[11] PROGMEM ="text/plain";
char http_shtml[ 6] PROGMEM =".shtml";
char index_html[12] PROGMEM ="/index.html";
const char httpd_mime_htm[] HTTPD_STRING_ATTR = "text/html";
const char httpd_mime_css[] HTTPD_STRING_ATTR = "text/css";
const char httpd_mime_png[] HTTPD_STRING_ATTR = "image/png";
const char httpd_mime_gif[] HTTPD_STRING_ATTR = "image/gif";
const char httpd_mime_jpg[] HTTPD_STRING_ATTR = "image/jpeg";
const char httpd_mime_txt[] HTTPD_STRING_ATTR = "text/plain";
const char httpd_mime_bin[] HTTPD_STRING_ATTR = "application/octet-stream";
const char httpd_jpg [] HTTPD_STRING_ATTR = "jpg";
const char httpd_shtml [] HTTPD_STRING_ATTR = ".shtml";
static
PT_THREAD(send_headers(struct httpd_state *s, char *statushdr))
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{
char *ptr;
PSOCK_BEGIN(&s->sout);
PSOCK_GENERATOR_SEND(&s->sout,generate_status_P,statushdr);
PSOCK_GENERATOR_SEND(&s->sout, generate_status, (char *)statushdr);
ptr = strrchr(s->filename, ISO_period);
if (pgm_read_byte_near(statushdr)=='4') {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_htm);
if (httpd_strncmp("4", statushdr, 1)==0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_htm );
} else if(ptr == NULL) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P,PSTR("application/octet-stream"));
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_bin );
} else {
ptr++;
if(strncmp_P(ptr, &http_htm[5],3)== 0 ||strncmp_P(ptr, &http_shtml[1], 4) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_htm );
} else if(strcmp_P(ptr, &http_css[5]) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_css );
} else if(strcmp_P(ptr, &http_png[6]) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_png );
} else if(strcmp_P(ptr, &http_gif[6])== 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_gif );
} else if(strcmp_P(ptr, PSTR("jpg")) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_jpg );
if(httpd_strncmp(ptr, &httpd_mime_htm[5],3)== 0 ||httpd_strncmp(ptr, &httpd_shtml[1], 4) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_htm );
} else if(httpd_strcmp(ptr, &httpd_mime_css[5]) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_css );
} else if(httpd_strcmp(ptr, &httpd_mime_png[6]) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_png );
} else if(httpd_strcmp(ptr, &httpd_mime_gif[6])== 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_gif );
} else if(httpd_strcmp(ptr, httpd_mime_jpg) == 0) {
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_jpg );
} else {
PSOCK_GENERATOR_SEND(&s->sout, generate_header_P, http_txt);
PSOCK_GENERATOR_SEND(&s->sout, generate_header, &httpd_mime_txt);
}
}
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
const char httpd_indexfn [] HTTPD_STRING_ATTR = "/index.html";
const char httpd_404fn [] HTTPD_STRING_ATTR = "/404.html";
const char httpd_404notf [] HTTPD_STRING_ATTR = "404 Not found";
const char httpd_200ok [] HTTPD_STRING_ATTR = "200 OK";
static
PT_THREAD(handle_output(struct httpd_state *s))
{
@ -349,17 +361,17 @@ PT_THREAD(handle_output(struct httpd_state *s))
PT_BEGIN(&s->outputpt);
#if DEBUGLOGIC
strcpy(s->filename,"/index.html");
httpd_strcpy(s->filename,httpd_indexfn);
#endif
if(!httpd_fs_open(s->filename, &s->file)) {
strcpy_P(s->filename, PSTR("/404.html"));
httpd_strcpy(s->filename, httpd_404fn);
httpd_fs_open(s->filename, &s->file);
PT_WAIT_THREAD(&s->outputpt, send_headers(s, PSTR("404 Not found")));
PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_404notf));
PT_WAIT_THREAD(&s->outputpt, send_file(s));
} else {
PT_WAIT_THREAD(&s->outputpt, send_headers(s, PSTR("200 OK")));
PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_200ok));
ptr = strchr(s->filename, ISO_period);
if((ptr != NULL && strncmp_P(ptr, http_shtml, 6) == 0) || strcmp_P(s->filename,index_html)==0) {
if((ptr != NULL && httpd_strncmp(ptr, httpd_shtml, 6) == 0) || httpd_strcmp(s->filename,httpd_indexfn)==0) {
PT_INIT(&s->scriptpt);
PT_WAIT_THREAD(&s->outputpt, handle_script(s));
} else {
@ -370,8 +382,8 @@ PT_THREAD(handle_output(struct httpd_state *s))
PT_END(&s->outputpt);
}
/*---------------------------------------------------------------------------*/
char http_get[4] PROGMEM ="GET ";
char http_ref[8] PROGMEM ="Referer:";
const char httpd_get[] HTTPD_STRING_ATTR = "GET ";
const char httpd_ref[] HTTPD_STRING_ATTR = "Referer:";
static
PT_THREAD(handle_input(struct httpd_state *s))
{
@ -380,7 +392,7 @@ PT_THREAD(handle_input(struct httpd_state *s))
PSOCK_READTO(&s->sin, ISO_space);
if(strncmp_P(s->inputbuf, http_get, 4) != 0) {
if(httpd_strncmp(s->inputbuf, httpd_get, 4) != 0) {
PSOCK_CLOSE_EXIT(&s->sin);
}
PSOCK_READTO(&s->sin, ISO_space);
@ -390,7 +402,7 @@ PT_THREAD(handle_input(struct httpd_state *s))
}
if(s->inputbuf[1] == ISO_space) {
strcpy_P(s->filename, index_html);
httpd_strcpy(s->filename, httpd_indexfn);
} else {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
@ -403,7 +415,7 @@ PT_THREAD(handle_input(struct httpd_state *s))
while(1) {
PSOCK_READTO(&s->sin, ISO_nl);
if(strncmp_P(s->inputbuf, http_ref, 8) == 0) {
if(httpd_strncmp(s->inputbuf, httpd_ref, 8) == 0) {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
webserver_log(s->inputbuf);

View File

@ -28,7 +28,7 @@
*
* This file is part of the uIP TCP/IP stack.
*
* $Id: httpd.h,v 1.3 2009/07/23 16:16:07 dak664 Exp $
* $Id: httpd.h,v 1.4 2009/07/24 15:41:52 dak664 Exp $
*
*/
@ -37,7 +37,8 @@
#include "contiki-net.h"
#include "httpd-fs.h"
#include "httpd-fs.h"
#include "lib/petsciiconv.h"
struct httpd_state {
unsigned char timer;
@ -55,7 +56,37 @@ struct httpd_state {
void *ptr;
} u;
};
/* httpd string storage is in RAM by default. Other storage can be defined here */
#define HTTPD_STRING_TYPE PROGMEM_TYPE
#define PROGMEM_TYPE 1
#define EEPROM_TYPE 2
#if HTTPD_STRING_TYPE==PROGMEM_TYPE
#define HTTPD_STRING_ATTR PROGMEM
/* These will fail if the server strings are above 64K in program flash */
#define httpd_memcpy memcpy_P
#define httpd_strcpy strcpy_P
#define httpd_strcmp strcmp_P
#define httpd_strncmp strncmp_P
#define httpd_strlen strlen_P
#define httpd_snprintf snprintf_P
#elif HTTPD_STRING_TYPE==EEPROM_TYPE
#define HTTPD_STRING_ATTR EEPROM
/* These are not implemented as yet */
#define httpd_memcpy memcpy_E
#define httpd_strcpy strcpy_E
#define httpd_strcmp strcmp_E
#define httpd_strncmp strncmp_E
#define httpd_strlen strlen_E
#define httpd_snprintf snprintf_E
#else
#define httpd_memcpy memcpy
#define httpd_strcpy strcpy
#define httpd_strcmp strcmp
#define httpd_strncmp strncmp
#define httpd_strlen strlen
#define httpd_snprintf snprintf
#endif
void httpd_init(void);
void httpd_appcall(void *state);