diff --git a/examples/thttpd/content/Makefile b/examples/thttpd/content/Makefile index 1e9937aa655..36974ad5a9e 100644 --- a/examples/thttpd/content/Makefile +++ b/examples/thttpd/content/Makefile @@ -33,7 +33,7 @@ # ############################################################################ -SUBDIRS = hello +SUBDIRS = hello tasks INSTALL_FILES = index.html style.css THTTPD_DIR = $(TOPDIR)/examples/thttpd diff --git a/examples/thttpd/content/hello/hello.c b/examples/thttpd/content/hello/hello.c index 9028d8fb90a..e1381799328 100644 --- a/examples/thttpd/content/hello/hello.c +++ b/examples/thttpd/content/hello/hello.c @@ -52,18 +52,29 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Hello requested from: %s\n", getenv("REMOTE_ADDR")); - (void)printf( + puts( "Content-type: text/html\r\n" "Status: 200/html\r\n" "\r\n" - "" - "
" - "Requested by: %s
" - "\r\n", - getenv("REMOTE_ADDR")); + "\r\n" + "\r\n" + "Requested by: %s
\r\n", + getenv("REMOTE_ADDR")); + puts( + "\r\n" + "\r\n"); return 0; } diff --git a/examples/thttpd/content/index.html b/examples/thttpd/content/index.html index 3c9d21f0083..1fba1fbf6d9 100644 --- a/examples/thttpd/content/index.html +++ b/examples/thttpd/content/index.html @@ -1,7 +1,7 @@ -\r\n" + "PID PRI SCHD TYPE NP STATE NAME\r\n"); + + sched_foreach(show_task, NULL); + + puts( + "\r\n" + "\r\n" + "\r\n"); + return 0; +} diff --git a/netutils/thttpd/fdwatch.c b/netutils/thttpd/fdwatch.c index 71e81c2b278..c59ce7799d5 100644 --- a/netutils/thttpd/fdwatch.c +++ b/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/netutils/thttpd/thttpd_cgi.c b/netutils/thttpd/thttpd_cgi.c index 7624bd22eb9..34e08f69a66 100755 --- a/netutils/thttpd/thttpd_cgi.c +++ b/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/netutils/thttpd/timers.c b/netutils/thttpd/timers.c index 7e67e6cbe96..0e19d1df2d5 100644 --- a/netutils/thttpd/timers.c +++ b/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);