Fix various issues, bad ages, etc. with ez80+uIP webserver

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1638 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-03-22 16:10:28 +00:00
parent 5cc7066b41
commit 85d77c281b
11 changed files with 751 additions and 757 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
############################################################################
# Make.defs
#
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
# Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
+8 -14
View File
@@ -76,9 +76,6 @@
#define ISO_slash 0x2f
#define ISO_colon 0x3a
#undef CONFIG_NETUTILS_HTTPD_DUMPBUFFER
#undef CONFIG_NETUTILS_HTTPD_DUMPPSTATE
/****************************************************************************
* Private Data
****************************************************************************/
@@ -186,7 +183,7 @@ static int handle_script(struct httpd_state *pstate)
int len;
char *ptr;
while(pstate->ht_file.len > 0)
while (pstate->ht_file.len > 0)
{
/* Check if we should start executing a script */
@@ -353,8 +350,10 @@ static int httpd_sendfile(struct httpd_state *pstate)
pstate->ht_sndlen = 0;
nvdbg("[%d] sending file '%s'\n", pstate->ht_sockfd, pstate->ht_filename);
if (!httpd_fs_open(pstate->ht_filename, &pstate->ht_file))
{
ndbg("[%d] '%s' not found\n", pstate->ht_sockfd, pstate->ht_filename);
memcpy(pstate->ht_filename, g_http404path, strlen(g_http404path));
httpd_fs_open(g_http404path, &pstate->ht_file);
if (send_headers(pstate, g_httpheader404, strlen(g_httpheader404)) == OK)
@@ -466,19 +465,14 @@ static void *httpd_handler(void *arg)
if (pstate)
{
/* Loop processing each HTTP command */
// do
{
/* Re-initialize the thread state structure */
/* Re-initialize the thread state structure */
memset(pstate, 0, sizeof(struct httpd_state));
pstate->ht_sockfd = sockfd;
memset(pstate, 0, sizeof(struct httpd_state));
pstate->ht_sockfd = sockfd;
/* Then handle the next httpd command */
/* Then handle the next httpd command */
ret = httpd_cmd(pstate);
}
// while (ret == OK);
ret = httpd_cmd(pstate);
/* End of command processing -- Clean up and exit */
+19 -14
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* netutils/webserver/httpd.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Based on uIP which also has a BSD style license:
@@ -53,7 +53,20 @@
* Definitions
****************************************************************************/
#define HTTPD_FS_STATISTICS 1
/* As threads are created to handle each request, a stack must be allocated
* for the thread. Use a default if the user provided no stacksize.
*/
#ifndef CONFIG_NETUTILS_HTTPDSTACKSIZE
# define CONFIG_NETUTILS_HTTPDSTACKSIZE 4096
#endif
#undef CONFIG_NETUTILS_HTTPDFSSTATS
#define CONFIG_NETUTILS_HTTPDFSSTATS 1
#ifndef CONFIG_NET_STATISTICS
# undef CONFIG_NETUTILS_HTTPDNETSTATS
#endif
/* For efficiency reasons, the size of the IO buffer should be a multiple
* of the TCP MSS value. Also, the current design requires that the IO
@@ -66,14 +79,6 @@
#define HTTPD_MAX_FILENAME 20
/* As threads are created to handle each request, a stack must be allocated
* for the thread. Use a default if the user provided no stacksize.
*/
#ifndef CONFIG_NETUTILS_HTTPDSTACKSIZE
# define CONFIG_NETUTILS_HTTPDSTACKSIZE 4096
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@@ -99,11 +104,11 @@ struct httpd_state
* Public Function Prototypes
****************************************************************************/
#ifdef HTTPD_FS_STATISTICS
#if HTTPD_FS_STATISTICS == 1
#ifdef CONFIG_NETUTILS_HTTPDFSSTATS
#if CONFIG_NETUTILS_HTTPDFSSTATS == 1
extern uint16 httpd_fs_count(char *name);
#endif /* HTTPD_FS_STATISTICS */
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
/* file must be allocated by caller and will be filled in by the function. */
+64 -103
View File
@@ -1,4 +1,5 @@
/* httpd_cgi.c
/****************************************************************************
* httpd_cgi.c
* Web server script interface
* Author: Adam Dunkels <adam@sics.se>
*
@@ -28,7 +29,12 @@
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdio.h>
#include <string.h>
@@ -41,134 +47,60 @@
#include "httpd_cgi.h"
#define CONFIG_HTTPDCGI_FILESTATS 1
#undef CONFIG_HTTPDCGI_DCPSTATS
#define CONFIG_HTTPDCGI_NETSTATS 1
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
HTTPD_CGI_CALL(file, "file-stats", file_stats);
#if CONFIG_HTTPDCGI_TCPSTATS
HTTPD_CGI_CALL(tcp, "tcp-connections", tcp_stats);
#endif
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
HTTPD_CGI_CALL(net, "net-stats", net_stats);
#endif
#if 0 /* Revisit */
static const struct httpd_cgi_call *calls[] = { &file, &tcp, &net, NULL };
#else
static const struct httpd_cgi_call *calls[] = {
#ifdef CONFIG_HTTPDCGI_FILESTATS
static const struct httpd_cgi_call *calls[] =
{
#ifdef CONFIG_NETUTILS_HTTPDFILESTATS
&file,
#endif
#ifdef CONFIG_HTTPDCGI_DCPSTATS
&tcp,
#endif
#ifdef CONFIG_HTTPDCGI_NETSTATS
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
&net,
#endif
NULL
};
#endif
static const char closed[] = /* "CLOSED",*/
{0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
{0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
static const char syn_rcvd[] = /* "SYN-RCVD",*/
{0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56, 0x44, 0};
{0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56, 0x44, 0};
static const char syn_sent[] = /* "SYN-SENT",*/
{0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e, 0x54, 0};
{0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e, 0x54, 0};
static const char established[] = /* "ESTABLISHED",*/
{0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x44, 0};
{0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x44, 0};
static const char fin_wait_1[] = /* "FIN-WAIT-1",*/
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x31, 0};
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x31, 0};
static const char fin_wait_2[] = /* "FIN-WAIT-2",*/
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x32, 0};
{0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x32, 0};
static const char closing[] = /* "CLOSING",*/
{0x43, 0x4c, 0x4f, 0x53, 0x49, 0x4e, 0x47, 0};
{0x43, 0x4c, 0x4f, 0x53, 0x49, 0x4e, 0x47, 0};
static const char time_wait[] = /* "TIME-WAIT,"*/
{0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41, 0x49, 0x54, 0};
{0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41, 0x49, 0x54, 0};
static const char last_ack[] = /* "LAST-ACK"*/
{0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43, 0x4b, 0};
{0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43, 0x4b, 0};
#if CONFIG_HTTPDCGI_TCPSTATS
static const char *states[] =
{
closed,
syn_rcvd,
syn_sent,
established,
fin_wait_1,
fin_wait_2,
closing,
time_wait,
last_ack
};
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
static void nullfunction(struct httpd_state *pstate, char *ptr)
{
}
httpd_cgifunction httpd_cgi(char *name)
{
const struct httpd_cgi_call **f;
/* Find the matching name in the table, return the function. */
for(f = calls; *f != NULL; ++f) {
if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {
return (*f)->function;
}
}
#ifdef CONFIG_CPP_HAVE_WARNING
# warning REVISIT -- must wait to return
#endif
return nullfunction;
}
#ifdef CONFIG_HTTPDCGI_FILESTATS
static void file_stats(struct httpd_state *pstate, char *ptr)
{
char buffer[16];
char *pcount = strchr(ptr, ' ') + 1;
snprintf(buffer, 16, "%5u", httpd_fs_count(pcount));
(void)send(pstate->ht_sockfd, buffer, strlen(buffer), 0);
}
#endif
#if CONFIG_HTTPDCGI_TCPSTATS
static void tcp_stats(struct httpd_state *pstate, char *ptr)
{
struct uip_conn *conn;
struct httpd_state *pstate = (struct httpd_state *)arg;
char buffer[256];
for(pstate->count = 0; pstate->count < CONFIG_NET_TCP_CONNS; ++pstate->count)
{
conn = &uip_conns[pstate->count];
if((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
{
snprintf(buffer, 25t,
"<tr><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
htons(conn->lport),
htons(conn->ripaddr[0]) >> 8,
htons(conn->ripaddr[0]) & 0xff,
htons(conn->ripaddr[1]) >> 8,
htons(conn->ripaddr[1]) & 0xff,
htons(conn->rport),
states[conn->tcpstateflags & UIP_TS_MASK],
conn->nrtx,
conn->timer,
(uip_outstanding(conn))? '*':' ',
(uip_stopped(conn))? '!':' ');
(void)send(pstate->sockout, buffer, strlen(buffer), 0);
}
}
}
#endif
#ifdef CONFIG_HTTPDCGI_NETSTATS
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
static void net_stats(struct httpd_state *pstate, char *ptr)
{
#ifdef CONFIG_NET_STATISTICS
char buffer[16];
int i;
@@ -177,6 +109,35 @@ static void net_stats(struct httpd_state *pstate, char *ptr)
snprintf(buffer, 16, "%5u\n", ((uip_stats_t *)&uip_stat)[i]);
send(pstate->ht_sockfd, buffer, strlen(buffer), 0);
}
#endif
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
httpd_cgifunction httpd_cgi(char *name)
{
const struct httpd_cgi_call **f;
/* Find the matching name in the table, return the function. */
for(f = calls; *f != NULL; ++f)
{
if(strncmp((*f)->name, name, strlen((*f)->name)) == 0)
{
return (*f)->function;
}
}
return nullfunction;
}
#ifdef CONFIG_NETUTILS_HTTPDFILESTATS
static void file_stats(struct httpd_state *pstate, char *ptr)
{
char buffer[16];
char *pcount = strchr(ptr, ' ') + 1;
snprintf(buffer, 16, "%5u", httpd_fs_count(pcount));
(void)send(pstate->ht_sockfd, buffer, strlen(buffer), 0);
}
#endif
+30 -14
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* netutils/webserver/httpd_fs.c
*
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Based on uIP which also has a BSD style license:
@@ -38,7 +38,7 @@
****************************************************************************/
/****************************************************************************
* Included Files
* Included Header Files
****************************************************************************/
#include <sys/types.h>
@@ -48,15 +48,27 @@
#include "httpd.h"
#include "httpd_fsdata.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef NULL
#define NULL 0
#endif /* NULL */
/****************************************************************************
* Private Data
****************************************************************************/
#include "httpd_fsdata.c"
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
static uint16 count[HTTPD_FS_NUMFILES];
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
/****************************************************************************
* Private Functions
****************************************************************************/
static uint8 httpd_fs_strcmp(const char *str1, const char *str2)
{
@@ -79,11 +91,15 @@ static uint8 httpd_fs_strcmp(const char *str1, const char *str2)
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
int httpd_fs_open(const char *name, struct httpd_fs_file *file)
{
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
uint16 i = 0;
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
struct httpd_fsdata_file_noconst *f;
for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
@@ -94,30 +110,30 @@ int httpd_fs_open(const char *name, struct httpd_fs_file *file)
{
file->data = f->data;
file->len = f->len;
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
++count[i];
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
return 1;
}
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
++i;
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
}
return 0;
}
void httpd_fs_init(void)
{
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
uint16 i;
for(i = 0; i < HTTPD_FS_NUMFILES; i++)
{
count[i] = 0;
}
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
}
#if HTTPD_FS_STATISTICS
#if CONFIG_NETUTILS_HTTPDFSSTATS
uint16 httpd_fs_count(char *name)
{
struct httpd_fsdata_file_noconst *f;
@@ -136,4 +152,4 @@ uint16 httpd_fs_count(char *name)
}
return 0;
}
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
File diff suppressed because it is too large Load Diff
+9 -9
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* netutils/webserver/httpd_fsdata.h
*
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Based on uIP which also has a BSD style license:
@@ -56,11 +56,11 @@ struct httpd_fsdata_file
FAR const ubyte *name;
FAR const ubyte *data;
int len;
#ifdef HTTPD_FS_STATISTICS
#if HTTPD_FS_STATISTICS == 1
#ifdef CONFIG_NETUTILS_HTTPDFSSTATS
#if CONFIG_NETUTILS_HTTPDFSSTATS == 1
uint16 count;
#endif /* HTTPD_FS_STATISTICS */
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
};
struct httpd_fsdata_file_noconst
@@ -69,11 +69,11 @@ struct httpd_fsdata_file_noconst
FAR char *name;
FAR char *data;
int len;
#ifdef HTTPD_FS_STATISTICS
#if HTTPD_FS_STATISTICS == 1
#ifdef CONFIG_NETUTILS_HTTPDFSSTATS
#if CONFIG_NETUTILS_HTTPDFSSTATS == 1
uint16 count;
#endif /* HTTPD_FS_STATISTICS */
#endif /* HTTPD_FS_STATISTICS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
#endif /* CONFIG_NETUTILS_HTTPDFSSTATS */
};
#endif /* __HTTPD_FSDATA_H__ */
+7 -10
View File
@@ -25,7 +25,7 @@ foreach $file (@files) {
if(-f $file) {
print "Adding file $file\n";
open(FILE, $file) || die "Could not open file $file\n";
$file =~ s-^-/-;
@@ -33,27 +33,24 @@ foreach $file (@files) {
$fvar =~ s-/-_-g;
$fvar =~ s-\.-_-g;
# for AVR, add PROGMEM here
print(OUTPUT "static const unsigned char data".$fvar."[] = {\n");
print(OUTPUT "\t/* $file */\n\t");
print(OUTPUT "static const unsigned char data".$fvar."[] =\n");
print(OUTPUT "{\n /* $file */\n\n ");
for($j = 0; $j < length($file); $j++) {
printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
}
printf(OUTPUT "0,\n");
printf(OUTPUT "0x00,\n ");
$i = 0;
while(read(FILE, $data, 1)) {
if($i == 0) {
print(OUTPUT "\t");
}
printf(OUTPUT "%#02x, ", unpack("C", $data));
$i++;
if($i == 10) {
print(OUTPUT "\n");
$i = 0;
print(OUTPUT " ");
}
}
print(OUTPUT "0};\n\n");
print(OUTPUT "0x00\n};\n\n");
close(FILE);
push(@fvars, $fvar);
push(@pfiles, $file);
@@ -74,5 +71,5 @@ for($i = 0; $i < @fvars; $i++) {
print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
}
print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
print(OUTPUT "#define HTTPD_FS_NUMFILES $i\n");