THTTPD progress

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2020 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2009-08-15 19:36:06 +00:00
parent c24bbb10f5
commit e1ec46aeca
6 changed files with 209 additions and 93 deletions
+1 -1
View File
@@ -543,7 +543,7 @@ CONFIG_THTTPD_CGI_STACKSIZE=1024
CONFIG_THTTPD_CGI_BYTECOUNT=20000
CONFIG_THTTPD_CGI_TIMELIMIT=0
CONFIG_THTTPD_CHARSET="iso-8859-1"
CONFIG_THTTPD_IOBUFFERSIZE=256
CONFIG_THTTPD_IOBUFFERSIZE=1024
#CONFIG_THTTPD_INDEX_NAMES
CONFIG_AUTH_FILE=n
CONFIG_THTTPD_LISTEN_BACKLOG=8
+2 -2
View File
@@ -54,10 +54,10 @@
#ifndef CONFIG_ARCH_STRCMP
int strcasecmp(const char *cs, const char *ct)
{
register signed char result;
register int result;
for (;;)
{
if ((result = toupper(*cs) - toupper(*ct)) != 0 || !*cs)
if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs)
{
break;
}
+2 -2
View File
@@ -54,10 +54,10 @@
#ifndef CONFIG_ARCH_STRNCASECMP
int strncasecmp(const char *cs, const char *ct, size_t nb)
{
register signed char result = 0;
register int result = 0;
for (; nb > 0; nb--)
{
if ((result = toupper(*cs) - toupper(*ct)) != 0 || !*cs)
if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs)
{
break;
}
File diff suppressed because it is too large Load Diff
+59 -10
View File
@@ -68,7 +68,58 @@
#define NEW(t,n) ((t*) malloc( sizeof(t) * (n) ))
#define RENEW(o,t,n) ((t*) realloc( (void*) o, sizeof(t) * (n) ))
/* Methods. */
/* Enable special instrumentation to track down "400 Bad Request" problems */
#undef CONFIG_THTTPD_BADREQUEST /* Define to enable "Bad Request" instrumentation */
#ifdef CONFIG_THTTPD_BADREQUEST
# if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_NET)
# undef CONFIG_THTTPD_BADREQUEST
# else
# define BADREQUEST(s) nvdbg("Bad Request: \"%s\"\n", s)
# endif
#endif
#ifndef CONFIG_THTTPD_BADREQUEST
# undef BADREQUEST
# define BADREQUEST(s)
#endif
/* Enable special instrumentation to track down "501 Not Implemented" problems */
#undef CONFIG_THTTPD_NOTIMPLEMENTED /* Define to enable "Not Implemented" instrumentation */
#ifdef CONFIG_THTTPD_NOTIMPLEMENTED
# if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_NET)
# undef CONFIG_THTTPD_NOTIMPLEMENTED
# else
# define NOTIMPLEMENTED(s) nvdbg("Not Implemented: \"%s\"\n", s)
# endif
#endif
#ifndef CONFIG_THTTPD_NOTIMPLEMENTED
# undef NOTIMPLEMENTED
# define NOTIMPLEMENTED(s)
#endif
/* Enable special instrumentation to track down "500 Internal Error" problems */
#undef CONFIG_THTTPD_INTERNALERROR /* Define to enable "Internal Error" instrumentation */
#ifdef CONFIG_THTTPD_INTERNALERROR
# if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_NET)
# undef CONFIG_THTTPD_INTERNALERROR
# else
# define INTERNALERROR(s) nvdbg("Internal Error: \"%s\"\n", s)
# endif
#endif
#ifndef CONFIG_THTTPD_INTERNALERROR
# undef INTERNALERROR
# define INTERNALERROR(s)
#endif
/* Methods */
#define METHOD_UNKNOWN 0
#define METHOD_GET 1
@@ -263,21 +314,19 @@ extern void httpd_destroy_conn(httpd_conn *hc);
/* Send an error message back to the client. */
extern void httpd_send_err(httpd_conn *hc, int status, char *title,
char *extraheads, char *form, char *arg);
extern void httpd_send_err(httpd_conn *hc, int status, const char *title,
const char *extraheads, const char *form, const char *arg);
/* Some error messages. */
extern char *httpd_err400title;
extern char *httpd_err400form;
extern char *httpd_err408title;
extern char *httpd_err408form;
extern char *httpd_err503title;
extern char *httpd_err503form;
extern const char httpd_err400title[];
extern const char httpd_err400form[];
extern const char httpd_err408title[];
extern const char httpd_err408form[];
/* Generate a string representation of a method number. */
extern char *httpd_method_str(int method);
extern const char *httpd_method_str(int method);
/* Reallocate a string. */
+10 -2
View File
@@ -307,6 +307,7 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
{
if (hc->read_size > CONFIG_THTTPD_MAXREALLOC)
{
BADREQUEST("MAXREALLOC");
goto errout_with_400;
}
httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->read_size + CONFIG_THTTPD_REALLOCINCR);
@@ -317,12 +318,13 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
sz = read(hc->conn_fd, &(hc->read_buf[hc->read_idx]), hc->read_size - hc->read_idx);
if (sz == 0)
{
BADREQUEST("EOF");
goto errout_with_400;
}
if (sz < 0)
{
/* Ignore EINTR and EAGAIN. Also ignore EWOULDBLOCK. At first glanc
/* Ignore EINTR and EAGAIN. Also ignore EWOULDBLOCK. At first glance
* you would think that connections returned by fdwatch as readable
* should never give an EWOULDBLOCK; however, this apparently can
* happen if a packet gets garbled.
@@ -332,6 +334,9 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
{
return;
}
ndbg("read(fd=%d) failed: %d\n", hc->conn_fd, errno);
BADREQUEST("read");
goto errout_with_400;
}
@@ -345,7 +350,8 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
case GR_NO_REQUEST:
return;
case GR_BAD_REQUEST:
goto errout_with_400;
BADREQUEST("httpd_got_request");
goto errout_with_400;
}
/* Yes. Try parsing and resolving it */
@@ -408,6 +414,7 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
if (actual != conn->offset)
{
ndbg("fseek to %d failed: offset=%d errno=%d\n", conn->offset, actual, errno);
BADREQUEST("lseek");
goto errout_with_400;
}
@@ -421,6 +428,7 @@ static void handle_read(struct connect_s *conn, struct timeval *tv)
return;
errout_with_400:
BADREQUEST("errout");
httpd_send_err(hc, 400, httpd_err400title, "", httpd_err400form, "");
errout_with_connection: