Extend apps/examples/thttpd so that it provides a index.cgi file the binfs file system is selected.

This commit is contained in:
Gregory Nutt 2015-06-02 14:26:08 -06:00
parent b3780a071c
commit 91ab8b0bc5
4 changed files with 40 additions and 18 deletions

View File

@ -44,7 +44,7 @@ PRIORITY = $(CONFIG_THTTPD_CGI_PRIORITY)
STACKSIZE = $(CONFIG_THTTPD_CGI_STACKSIZE)
ASRCS =
CSRCS = hello.c netstat.c tasks.c
CSRCS = index.c hello.c netstat.c tasks.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
@ -68,9 +68,8 @@ else
INSTALL_DIR = $(BIN_DIR)
endif
ROOTDEPPATH = --dep-path hello --dep-path netstat --dep-path tasks
VPATH = hello:netstat:tasks
ROOTDEPPATH = --dep-path index --dep-path hello --dep-path netstat --dep-path tasks
VPATH = index:hello:netstat:tasks
all: .built
.PHONY: context headers binaries depend clean
@ -89,6 +88,9 @@ binaries: .built
headers:
$(BUILTIN_REGISTRY)$(DELIM)index_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,index.cgi,$(PRIORITY),$(STACKSIZE),index_main)
$(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,hello,$(PRIORITY),$(STACKSIZE),hello_main)
@ -98,7 +100,7 @@ $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat: $(DEPCONFIG) Makefile
$(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,tasks,$(PRIORITY),$(STACKSIZE),tasks_main)
context: $(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat $(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat
context: $(BUILTIN_REGISTRY)$(DELIM)index_main.bdat $(BUILTIN_REGISTRY)$(DELIM)hello_main.bdat $(BUILTIN_REGISTRY)$(DELIM)netstat_main.bdat $(BUILTIN_REGISTRY)$(DELIM)tasks_main.bdat
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -64,6 +64,10 @@
# include <nuttx/binfmt/nxflat.h>
#endif
#ifdef CONFIG_THTTPD_BINFS
# include <nuttx/binfmt/builtin.h>
#endif
#ifdef CONFIG_NET_SLIP
# include <nuttx/net/net.h>
#endif
@ -249,6 +253,7 @@ int thttp_main(int argc, char *argv[])
/* Create a ROM disk for the ROMFS filesystem */
printf("Registering romdisk\n");
ret = romdisk_register(0, (uint8_t*)romfs_img, NSECTORS(romfs_img_len), SECTORSIZE);
if (ret < 0)
{
@ -272,6 +277,17 @@ int thttp_main(int argc, char *argv[])
#endif
#ifdef CONFIG_THTTPD_BINFS
/* Initialize the NXFLAT binary loader */
printf("Initializing the Built-In binary loader\n");
ret = builtin_initialize();
if (ret < 0)
{
printf("ERROR: Initialization of the Built-In loader failed: %d\n", ret);
exit(2);
}
/* Mount the BINFS file system */
printf("Mounting BINFS filesystem at target=%s\n", MOUNTPT);

View File

@ -3230,11 +3230,13 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowP)
}
/* Nope, no index file, so it's an actual directory request. */
#ifdef CONFIG_THTTPD_GENERATE_INDICES
/* Directories must be readable for indexing. */
if (!(hc->sb.st_mode & S_IROTH))
{
ndbg("%s URL \"%s\" tried to index a directory with indexing disabled\n",
ndbg("%s URL \"%s\" tried to index a non-readable directory\n",
httpd_ntoa(&hc->client_addr), hc->encodedurl);
httpd_send_err(hc, 403, err403title, "",
ERROR_FORM(err403form,
@ -3262,8 +3264,9 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowP)
return ls(hc);
#else /* CONFIG_THTTPD_GENERATE_INDICES */
/* Indexing is disabled */
ndbg("%s URL \"%s\" tried to index a directory\n",
ndbg("%s URL \"%s\" tried to index a directory with indexing disabled\n",
httpd_ntoa(&hc->client_addr), hc->encodedurl);
httpd_send_err(hc, 403, err403title, "",
ERROR_FORM(err403form,

View File

@ -129,7 +129,7 @@ static void create_environment(httpd_conn *hc);
static char **make_argp(httpd_conn *hc);
static inline int cgi_interpose_input(struct cgi_conn_s *cc);
static inline int cgi_interpose_output(struct cgi_conn_s *cc);
static int cgi_child(int argc, char **argv);
static int cgi_child(int argc, char **argv);
/****************************************************************************
* Private Data
@ -720,7 +720,7 @@ static int cgi_child(int argc, char **argv)
cc = (FAR struct cgi_conn_s*)httpd_malloc(sizeof(struct cgi_conn_s));
if (!cc)
{
nlldbg("cgi_conn allocation failed\n");
nlldbg("ERROR: cgi_conn allocation failed\n");
close(hc->conn_fd);
goto errout;
}
@ -768,7 +768,7 @@ static int cgi_child(int argc, char **argv)
ret = pipe(pipefd);
if (ret < 0)
{
nlldbg("STDIN pipe: %d\n", errno);
nlldbg("ERROR: STDIN pipe: %d\n", errno);
goto errout_with_cgiconn;
}
else
@ -784,7 +784,7 @@ static int cgi_child(int argc, char **argv)
if (ret < 0)
{
nlldbg("STDIN dup2: %d\n", errno);
nlldbg("ERROR: STDIN dup2: %d\n", errno);
goto errout_with_descriptors;
}
}
@ -799,7 +799,7 @@ static int cgi_child(int argc, char **argv)
ret = pipe(pipefd);
if (ret < 0)
{
nlldbg("STDOUT pipe: %d\n", errno);
nlldbg("ERROR: STDOUT pipe: %d\n", errno);
goto errout_with_descriptors;
}
else
@ -815,7 +815,7 @@ static int cgi_child(int argc, char **argv)
if (ret < 0)
{
nlldbg("STDOUT dup2: %d\n", errno);
nlldbg("ERROR: STDOUT dup2: %d\n", errno);
goto errout_with_descriptors;
}
}
@ -833,6 +833,7 @@ static int cgi_child(int argc, char **argv)
{
(void)chdir(directory); /* ignore errors */
}
httpd_free(dupname);
}
@ -841,7 +842,7 @@ static int cgi_child(int argc, char **argv)
httpd_realloc_str(&cc->outbuf.buffer, &cc->outbuf.size, CONFIG_THTTPD_CGIOUTBUFFERSIZE);
if (!cc->outbuf.buffer)
{
nlldbg("hdr allocation failed\n");
nlldbg("ERROR: hdr allocation failed\n");
goto errout_with_descriptors;
}
@ -850,7 +851,7 @@ static int cgi_child(int argc, char **argv)
fw = fdwatch_initialize(2);
if (!fw)
{
nlldbg("fdwatch allocation failed\n");
nlldbg("ERROR: fdwatch allocation failed\n");
goto errout_with_outbuffer;
}
@ -867,7 +868,7 @@ static int cgi_child(int argc, char **argv)
{
/* Something went wrong. */
nlldbg("execve %s: %d\n", hc->expnfilename, errno);
nlldbg("ERROR: execve %s: %d\n", hc->expnfilename, errno);
goto errout_with_watch;
}
@ -877,7 +878,7 @@ static int cgi_child(int argc, char **argv)
client_data.i = child;
if (tmr_create(NULL, cgi_kill, client_data, CONFIG_THTTPD_CGI_TIMELIMIT * 1000L, 0) == NULL)
{
nlldbg("tmr_create(cgi_kill child) failed\n");
nlldbg("ERROR: tmr_create(cgi_kill child) failed\n");
goto errout_with_watch;
}
#endif
@ -895,7 +896,7 @@ static int cgi_child(int argc, char **argv)
{
if (httpd_write(cc->wrfd, &(hc->read_buf[hc->checked_idx]), nbytes) != nbytes)
{
nlldbg("httpd_write failed\n");
nlldbg("ERROR: httpd_write failed\n");
return 1;
}
}