Changes to raven-webserver by "David Kopf" <dak664@embarqmail.com>:
*Fixed bug in the cgi script handling *Making a special check for index.html and treating it like index.shtml to allow a common header for all files. *adding robots.txt to keep google, msn, yahoo out *adding a nice icon through a <link rel="icon"... in the header *saying "not enabled" for temperature if it hasn't been initialized
This commit is contained in:
parent
e362e2b99e
commit
a0a9ccf2db
8 changed files with 371 additions and 408 deletions
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd-cgi.c,v 1.1 2008/10/14 10:14:13 julienabeille Exp $
|
||||
* $Id: httpd-cgi.c,v 1.2 2008/11/16 15:28:37 c_oflynn Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -51,8 +51,8 @@
|
|||
#include "httpd-fs.h"
|
||||
|
||||
#include "lib/petsciiconv.h"
|
||||
|
||||
#include "sensors.h"
|
||||
|
||||
#include "sensors.h"
|
||||
|
||||
static struct httpd_cgi_call *calls = NULL;
|
||||
|
||||
|
@ -98,10 +98,10 @@ static const char tcp_name[] = /* "tcp-connections"*/
|
|||
0x73, 0};
|
||||
static const char proc_name[] = /* "processes"*/
|
||||
{0x70, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73,
|
||||
0x65, 0x73, 0};
|
||||
|
||||
static const char sensor_name[] = "sensors";
|
||||
|
||||
0x65, 0x73, 0};
|
||||
|
||||
static const char sensor_name[] = "sensors";
|
||||
|
||||
char sensor_temperature[12];
|
||||
|
||||
static const char *states[] = {
|
||||
|
@ -116,15 +116,15 @@ static const char *states[] = {
|
|||
last_ack,
|
||||
none,
|
||||
running,
|
||||
called};
|
||||
|
||||
called};
|
||||
|
||||
uint8_t sprint_ip6(uip_ip6addr_t addr, char * result);
|
||||
|
||||
|
||||
void
|
||||
web_set_temp(char *s)
|
||||
{
|
||||
strcpy(sensor_temperature, s);
|
||||
strcpy(sensor_temperature, s);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -153,15 +153,29 @@ static unsigned short
|
|||
generate_file_stats(void *arg)
|
||||
{
|
||||
char *f = (char *)arg;
|
||||
return snprintf((char *)uip_appdata, uip_mss(), "%5u", httpd_fs_count(f));
|
||||
int i;
|
||||
char tmp[20];
|
||||
// for (i=0;i<20;i++) if (pgm_read_byte(f++)==' ') break; //skip file-stats string
|
||||
for (i=0;i<19;i++) {
|
||||
tmp[i]=pgm_read_byte(f++); //transfer "/filename" to RAM
|
||||
if (tmp[i]==' ') {
|
||||
tmp[i]=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// return sprintf_P((char *)uip_appdata, PSTR( "%s"), tmp); //show file name for debugging
|
||||
return snprintf_P((char *)uip_appdata, uip_mss(), PSTR("%5u"), httpd_fs_count(tmp));
|
||||
// return snprintf_P((char *)uip_appdata, uip_mss(), PSTR("%5u"), httpd_fs_count(f));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
|
||||
{
|
||||
|
||||
PSOCK_BEGIN(&s->sout);
|
||||
|
||||
PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) (strchr(ptr, ' ') + 1));
|
||||
//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);
|
||||
}
|
||||
|
@ -171,25 +185,25 @@ make_tcp_stats(void *arg)
|
|||
{
|
||||
struct uip_conn *conn;
|
||||
struct httpd_state *s = (struct httpd_state *)arg;
|
||||
|
||||
uint16_t numprinted;
|
||||
|
||||
uint16_t numprinted;
|
||||
|
||||
conn = &uip_conns[s->u.count];
|
||||
|
||||
conn = &uip_conns[s->u.count];
|
||||
|
||||
numprinted = snprintf((char *)uip_appdata, uip_mss(),
|
||||
"<tr align=\"center\"><td>%d</td><td>",
|
||||
htons(conn->lport));
|
||||
|
||||
numprinted += sprint_ip6(conn->ripaddr, uip_appdata + numprinted);
|
||||
numprinted += snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted,
|
||||
"<tr align=\"center\"><td>%d</td><td>",
|
||||
htons(conn->lport));
|
||||
|
||||
numprinted += sprint_ip6(conn->ripaddr, uip_appdata + numprinted);
|
||||
numprinted += snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted,
|
||||
"-%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
|
||||
htons(conn->rport),
|
||||
states[conn->tcpstateflags & UIP_TS_MASK],
|
||||
conn->nrtx,
|
||||
conn->timer,
|
||||
(uip_outstanding(conn))? '*':' ',
|
||||
(uip_stopped(conn))? '!':' ');
|
||||
|
||||
(uip_stopped(conn))? '!':' ');
|
||||
|
||||
return numprinted;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -216,8 +230,8 @@ make_processes(void *p)
|
|||
strncpy(name, ((struct process *)p)->name, 40);
|
||||
petsciiconv_toascii(name, 40);
|
||||
|
||||
return snprintf((char *)uip_appdata, uip_mss(),
|
||||
"<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n",
|
||||
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,
|
||||
*((char **)&(((struct process *)p)->thread)),
|
||||
states[9 + ((struct process *)p)->state]);
|
||||
|
@ -231,12 +245,13 @@ PT_THREAD(processes(struct httpd_state *s, char *ptr))
|
|||
PSOCK_GENERATOR_SEND(&s->sout, make_processes, s->u.ptr);
|
||||
}
|
||||
PSOCK_END(&s->sout);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short
|
||||
generate_sensor_readings(void *arg)
|
||||
{
|
||||
return snprintf((char *)uip_appdata, uip_mss(), "<em>Temperature:</em> %s\n", sensor_temperature);
|
||||
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
|
||||
|
@ -266,7 +281,7 @@ httpd_cgi_add(struct httpd_cgi_call *c)
|
|||
|
||||
HTTPD_CGI_CALL(file, file_name, file_stats);
|
||||
HTTPD_CGI_CALL(tcp, tcp_name, tcp_stats);
|
||||
HTTPD_CGI_CALL(proc, proc_name, processes);
|
||||
HTTPD_CGI_CALL(proc, proc_name, processes);
|
||||
HTTPD_CGI_CALL(sensors, sensor_name, sensor_readings);
|
||||
|
||||
void
|
||||
|
@ -274,57 +289,57 @@ httpd_cgi_init(void)
|
|||
{
|
||||
httpd_cgi_add(&file);
|
||||
httpd_cgi_add(&tcp);
|
||||
httpd_cgi_add(&proc);
|
||||
httpd_cgi_add(&proc);
|
||||
httpd_cgi_add(&sensors);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
uint8_t sprint_ip6(uip_ip6addr_t addr, char * result)
|
||||
{
|
||||
unsigned char zerocnt = 0;
|
||||
unsigned char numprinted = 0;
|
||||
char * starting = result;
|
||||
|
||||
unsigned char i = 0;
|
||||
|
||||
while (numprinted < 8)
|
||||
{
|
||||
//Address is zero, have we used our ability to
|
||||
//replace a bunch with : yet?
|
||||
if ((addr.u16[i] == 0) && (zerocnt == 0))
|
||||
{
|
||||
//How mant zeros?
|
||||
zerocnt = 0;
|
||||
while(addr.u16[zerocnt + i] == 0)
|
||||
zerocnt++;
|
||||
|
||||
//just one, don't waste our zeros...
|
||||
if (zerocnt == 1)
|
||||
{
|
||||
*result++ = '0';
|
||||
numprinted++;
|
||||
break;
|
||||
}
|
||||
|
||||
//Cool - can replace a bunch of zeros
|
||||
i += zerocnt;
|
||||
numprinted += zerocnt;
|
||||
}
|
||||
//Normal address, just print it
|
||||
else
|
||||
{
|
||||
result += sprintf(result, "%x", (unsigned int)(ntohs(addr.u16[i])));
|
||||
i++;
|
||||
numprinted++;
|
||||
}
|
||||
|
||||
//Don't print : on last one
|
||||
if (numprinted != 8)
|
||||
*result++ = ':';
|
||||
}
|
||||
|
||||
return (result - starting);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint8_t sprint_ip6(uip_ip6addr_t addr, char * result)
|
||||
{
|
||||
unsigned char zerocnt = 0;
|
||||
unsigned char numprinted = 0;
|
||||
char * starting = result;
|
||||
|
||||
unsigned char i = 0;
|
||||
|
||||
while (numprinted < 8)
|
||||
{
|
||||
//Address is zero, have we used our ability to
|
||||
//replace a bunch with : yet?
|
||||
if ((addr.u16[i] == 0) && (zerocnt == 0))
|
||||
{
|
||||
//How mant zeros?
|
||||
zerocnt = 0;
|
||||
while(addr.u16[zerocnt + i] == 0)
|
||||
zerocnt++;
|
||||
|
||||
//just one, don't waste our zeros...
|
||||
if (zerocnt == 1)
|
||||
{
|
||||
*result++ = '0';
|
||||
numprinted++;
|
||||
break;
|
||||
}
|
||||
|
||||
//Cool - can replace a bunch of zeros
|
||||
i += zerocnt;
|
||||
numprinted += zerocnt;
|
||||
}
|
||||
//Normal address, just print it
|
||||
else
|
||||
{
|
||||
result += sprintf(result, "%x", (unsigned int)(ntohs(addr.u16[i])));
|
||||
i++;
|
||||
numprinted++;
|
||||
}
|
||||
|
||||
//Don't print : on last one
|
||||
if (numprinted != 8)
|
||||
*result++ = ':';
|
||||
}
|
||||
|
||||
return (result - starting);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue