diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-09-16 15:04:58 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-09-16 15:04:58 +0000 |
commit | 56b549a07277af7e0cffad11a6025e0a5ca5bf28 (patch) | |
tree | 30f70ae0d21d0fd0c4b135386bcbf271174b9754 /nuttx/netutils/thttpd | |
parent | 22de6d5b99468199dd36c2839572df4d6c35f28e (diff) | |
download | px4-nuttx-56b549a07277af7e0cffad11a6025e0a5ca5bf28.tar.gz px4-nuttx-56b549a07277af7e0cffad11a6025e0a5ca5bf28.tar.bz2 px4-nuttx-56b549a07277af7e0cffad11a6025e0a5ca5bf28.zip |
THTTPD CGI works
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2063 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils/thttpd')
-rw-r--r-- | nuttx/netutils/thttpd/fdwatch.c | 73 | ||||
-rwxr-xr-x | nuttx/netutils/thttpd/thttpd_cgi.c | 18 | ||||
-rw-r--r-- | nuttx/netutils/thttpd/timers.c | 4 |
3 files changed, 64 insertions, 31 deletions
diff --git a/nuttx/netutils/thttpd/fdwatch.c b/nuttx/netutils/thttpd/fdwatch.c index 71e81c2b2..c59ce7799 100644 --- a/nuttx/netutils/thttpd/fdwatch.c +++ b/nuttx/netutils/thttpd/fdwatch.c @@ -56,6 +56,37 @@ * Pre-Processor Definitions ****************************************************************************/ +/* Debug output from this file is normally suppressed. If enabled, be aware + * that output to stdout will interfere with CGI programs (you could use the + * the low-level debug (lldbg) functions which probably do not use stdout + */ + +#ifdef CONFIG_THTTPD_FDWATCH_DEBUG +# ifdef CONFIG_CPP_HAVE_VARARGS +# define fwdbg(format, arg...) ndbg(format, ##arg) +# define fwlldbg(format, arg...) nlldbg(format, ##arg) +# define fwvdbg(format, arg...) nvdbg(format, ##arg) +# define fwllvdbg(format, arg...) nllvdbg(format, ##arg) +# else +# define fwdbg ndbg +# define fwlldbg nlldbg +# define fwvdbg nvdbg +# define fwllvdbg nllvdbg +# endif +#else +# ifdef CONFIG_CPP_HAVE_VARARGS +# define fwdbg(x...) +# define fwlldbg(x...) +# define fwvdbg(x...) +# define fwllvdbg(x...) +# else +# define fwdbg (void) +# define fwlldbg (void) +# define fwvdbg (void) +# define fwllvdbg (void) +# endif +#endif + #ifndef MIN # define MIN(a,b) ((a) < (b) ? (a) : (b)) #endif @@ -77,18 +108,18 @@ static void fdwatch_dump(const char *msg, FAR struct fdwatch_s *fw) { int i; - nvdbg("%s\n", msg); - nvdbg("nwatched: %d nfds: %d\n", fw->nwatched, fw->nfds); + fwvdbg("%s\n", msg); + fwvdbg("nwatched: %d nfds: %d\n", fw->nwatched, fw->nfds); for (i = 0; i < fw->nwatched; i++) { - nvdbg("%2d. pollfds: {fd: %d events: %02x revents: %02x} client: %p\n", - i+1, fw->pollfds[i].fd, fw->pollfds[i].events, - fw->pollfds[i].revents, fw->client[i]); + fwvdbg("%2d. pollfds: {fd: %d events: %02x revents: %02x} client: %p\n", + i+1, fw->pollfds[i].fd, fw->pollfds[i].events, + fw->pollfds[i].revents, fw->client[i]); } - nvdbg("nactive: %d next: %d\n", fw->nactive, fw->next); + fwvdbg("nactive: %d next: %d\n", fw->nactive, fw->next); for (i = 0; i < fw->nactive; i++) { - nvdbg("%2d. %d active\n", i, fw->ready[i]); + fwvdbg("%2d. %d active\n", i, fw->ready[i]); } } #else @@ -105,12 +136,12 @@ static int fdwatch_pollndx(FAR struct fdwatch_s *fw, int fd) { if (fw->pollfds[pollndx].fd == fd) { - nvdbg("pollndx: %d\n", pollndx); + fwvdbg("pollndx: %d\n", pollndx); return pollndx; } } - ndbg("No poll index for fd %d: %d\n", fd); + fwdbg("No poll index for fd %d: %d\n", fd); return -1; } @@ -129,7 +160,7 @@ struct fdwatch_s *fdwatch_initialize(int nfds) fw = (struct fdwatch_s*)zalloc(sizeof(struct fdwatch_s)); if (!fw) { - ndbg("Failed to allocate fdwatch\n"); + fwdbg("Failed to allocate fdwatch\n"); return NULL; } @@ -193,12 +224,12 @@ void fdwatch_uninitialize(struct fdwatch_s *fw) void fdwatch_add_fd(struct fdwatch_s *fw, int fd, void *client_data) { - nvdbg("fd: %d client_data: %p\n", fd, client_data); + fwvdbg("fd: %d client_data: %p\n", fd, client_data); fdwatch_dump("Before adding:", fw); if (fw->nwatched >= fw->nfds) { - ndbg("too many fds\n"); + fwdbg("too many fds\n"); return; } @@ -220,7 +251,7 @@ void fdwatch_del_fd(struct fdwatch_s *fw, int fd) { int pollndx; - nvdbg("fd: %d\n", fd); + fwvdbg("fd: %d\n", fd); fdwatch_dump("Before deleting:", fw); /* Get the index associated with the fd */ @@ -261,11 +292,11 @@ int fdwatch(struct fdwatch_s *fw, long timeout_msecs) */ fdwatch_dump("Before waiting:", fw); - nvdbg("Waiting... (timeout %d)\n", timeout_msecs); + fwvdbg("Waiting... (timeout %d)\n", timeout_msecs); fw->nactive = 0; fw->next = 0; ret = poll(fw->pollfds, fw->nwatched, (int)timeout_msecs); - nvdbg("Awakened: %d\n", ret); + fwvdbg("Awakened: %d\n", ret); /* Look through all of the descriptors and make a list of all of them than * have activity. @@ -281,7 +312,7 @@ int fdwatch(struct fdwatch_s *fw, long timeout_msecs) { /* Yes... save it in a shorter list */ - nvdbg("pollndx: %d fd: %d revents: %04x\n", + fwvdbg("pollndx: %d fd: %d revents: %04x\n", i, fw->pollfds[i].fd, fw->pollfds[i].revents); fw->ready[fw->nactive++] = fw->pollfds[i].fd; @@ -297,7 +328,7 @@ int fdwatch(struct fdwatch_s *fw, long timeout_msecs) /* Return the number of descriptors with activity */ - nvdbg("nactive: %d\n", fw->nactive); + fwvdbg("nactive: %d\n", fw->nactive); fdwatch_dump("After wakeup:", fw); return ret; } @@ -308,7 +339,7 @@ int fdwatch_check_fd(struct fdwatch_s *fw, int fd) { int pollndx; - nvdbg("fd: %d\n", fd); + fwvdbg("fd: %d\n", fd); fdwatch_dump("Checking:", fw); /* Get the index associated with the fd */ @@ -319,7 +350,7 @@ int fdwatch_check_fd(struct fdwatch_s *fw, int fd) return fw->pollfds[pollndx].revents & (POLLIN | POLLHUP | POLLNVAL); } - nvdbg("POLLERR fd: %d\n", fd); + fwvdbg("POLLERR fd: %d\n", fd); return 0; } @@ -328,11 +359,11 @@ void *fdwatch_get_next_client_data(struct fdwatch_s *fw) fdwatch_dump("Before getting client data:", fw); if (fw->next >= fw->nwatched) { - nvdbg("All client data returned: %d\n", fw->next); + fwvdbg("All client data returned: %d\n", fw->next); return (void*)-1; } - nvdbg("client_data[%d]: %p\n", fw->next, fw->client[fw->next]); + fwvdbg("client_data[%d]: %p\n", fw->next, fw->client[fw->next]); return fw->client[fw->next++]; } diff --git a/nuttx/netutils/thttpd/thttpd_cgi.c b/nuttx/netutils/thttpd/thttpd_cgi.c index 7624bd22e..34e08f69a 100755 --- a/nuttx/netutils/thttpd/thttpd_cgi.c +++ b/nuttx/netutils/thttpd/thttpd_cgi.c @@ -491,7 +491,7 @@ static inline int cgi_interpose_output(struct cgi_conn_s *cc) httpd_realloc_str(&cc->outbuf.buffer, &cc->outbuf.size, cc->outbuf.len + nbytes_read);
(void)memcpy(&(cc->outbuf.buffer[cc->outbuf.len]), cc->inbuf.buffer, nbytes_read);
- cc->outbuf.len += nbytes_read;
+ cc->outbuf.len += nbytes_read;
cc->outbuf.buffer[cc->outbuf.len] = '\0';
nllvdbg("Header bytes accumulated: %d\n", cc->outbuf.len);
@@ -505,15 +505,17 @@ static inline int cgi_interpose_output(struct cgi_conn_s *cc) }
else
{
- /* Return. We will be called again when more data is available
- * on the socket.
+ /* All of the headers have not yet been read ... Return. We
+ * will be called again when more data is available in the pipe
+ * connected to the CGI task.
*/
return 0;
}
}
}
- break;
+
+ /* Otherwise, fall through and parse status in the HTTP headers */
case CGI_OUTBUFFER_HEADERREAD:
{
@@ -587,7 +589,7 @@ static inline int cgi_interpose_output(struct cgi_conn_s *cc) title = err404title;
break;
- case 408:
+ case 408:
title = httpd_err408title;
break;
@@ -650,6 +652,10 @@ static inline int cgi_interpose_output(struct cgi_conn_s *cc) return 1;
}
}
+ else
+ {
+ cgi_dumpbuffer("Received from CGI:", cc->inbuf.buffer, nbytes_read);
+ }
}
while (nbytes_read < 0);
@@ -667,7 +673,7 @@ static inline int cgi_interpose_output(struct cgi_conn_s *cc) {
/* Forward the data from the CGI program to the client */
- (void)httpd_write(cc->connfd, cc->inbuf.buffer, strlen(cc->inbuf.buffer));
+ (void)httpd_write(cc->connfd, cc->inbuf.buffer, nbytes_read);
}
}
break;
diff --git a/nuttx/netutils/thttpd/timers.c b/nuttx/netutils/thttpd/timers.c index 7e67e6cbe..0e19d1df2 100644 --- a/nuttx/netutils/thttpd/timers.c +++ b/nuttx/netutils/thttpd/timers.c @@ -233,8 +233,6 @@ Timer *tmr_create(struct timeval *now, TimerProc *timer_proc, /* Add the new timer to the proper active list. */ l_add(tmr); - - nvdbg("Return: %p\n", tmr); return tmr; } @@ -330,8 +328,6 @@ void tmr_run(struct timeval *now) void tmr_cancel(Timer *tmr) { - nvdbg("tmr: %p\n", tmr); - /* Remove it from its active list. */ l_remove(tmr); |