9
0
Fork 0

Initialize THTTPD integration changes

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@2006 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2009-08-02 15:08:09 +00:00
parent 2a7e788615
commit 13f242d60c
6 changed files with 43 additions and 28 deletions

View File

@ -70,10 +70,10 @@ install: $(foreach DIR, $(SUBDIRS), $(DIR)_install)
# Create the romfs directory
$(ROMFS_DIR):
@mkdir $(ROMFS_DIR)
@mkdir -p $(ROMFS_DIR)
$(ROMFSCGI_DIR): $(ROMFS_DIR)
@mkdir $(ROMFSCGI_DIR)
@mkdir -p $(ROMFSCGI_DIR)
# Populate the romfs directory

View File

@ -228,7 +228,8 @@ int user_start(int argc, char *argv[])
g_thttpdsymtab = exports;
g_thttpdnsymbols = NEXPORTS;
printf("Starting THTTPD\n");
message("Starting THTTPD\n");
thttpd_main(1, &thttpd_argv);
message("THTTPD terminated\n");
return 0;
}

View File

@ -245,8 +245,9 @@ int net_close(int sockfd)
{
/* Yes... free the connection structure */
uip_unlisten(conn); /* No longer accepting connections */
uip_unlisten(conn); /* No longer accepting connections */
netclose_disconnect(psock); /* Break any current connections */
conn->crefs = 0; /* No more references on the connection */
uip_tcpfree(conn); /* Free uIP resources */
}
else

View File

@ -272,16 +272,19 @@ char *httpd_err503form = "The requested URL '%s' is temporarily overloaded.
static void free_httpd_server(httpd_server * hs)
{
if (hs->binding_hostname)
if (hs)
{
free((void *)hs->binding_hostname);
}
if (hs->hostname)
{
free(hs->hostname);
}
if (hs->cwd)
{
free((void *)hs->cwd);
if (hs->cwd)
{
free(hs->cwd);
}
free(hs);
}
free((void *)hs);
}
static int initialize_listen_socket(httpd_sockaddr *saP)
@ -300,10 +303,11 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Create socket. */
nvdbg("Create listen socket\n");
listen_fd = socket(saP->sin_family, SOCK_STREAM, 0);
if (listen_fd < 0)
{
ndbg("socket %s: %d\n", httpd_ntoa(saP), errno);
ndbg("socket failed: %d\n", errno);
return -1;
}
@ -312,14 +316,14 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
on = 1;
if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
{
ndbg("setsockopt SO_REUSEADDR: %d\n", errno);
ndbg("setsockopt(SO_REUSEADDR) failed: %d\n", errno);
}
/* Bind to it. */
if (bind(listen_fd, (struct sockaddr*)&saP, sockaddr_len(saP)) < 0)
{
ndbg("bind %s: %d\n", httpd_ntoa(saP), errno);
ndbg("bind to %s failed: %d\n", httpd_ntoa(saP), errno);
(void)close(listen_fd);
return -1;
}
@ -329,14 +333,14 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
flags = fcntl(listen_fd, F_GETFL, 0);
if (flags == -1)
{
ndbg("fcntl F_GETFL: %d\n", errno);
ndbg("fcntl(F_GETFL) failed: %d\n", errno);
(void)close(listen_fd);
return -1;
}
if (fcntl(listen_fd, F_SETFL, flags | O_NDELAY) < 0)
{
ndbg("fcntl O_NDELAY: %d\n", errno);
ndbg("fcntl(O_NDELAY) failed: %d\n", errno);
(void)close(listen_fd);
return -1;
}
@ -345,7 +349,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
if (listen(listen_fd, CONFIG_THTTPD_LISTEN_BACKLOG) < 0)
{
ndbg("listen: %d\n", errno);
ndbg("listen failed: %d\n", errno);
(void)close(listen_fd);
return -1;
}
@ -2053,7 +2057,7 @@ static void create_environment(httpd_conn *hc)
else
#endif
{
cp = hc->hs->server_hostname;
cp = hc->hs->hostname;
}
if (cp)
@ -3163,7 +3167,7 @@ static int check_referer(httpd_conn *hc)
else
#endif
{
cp = hc->hs->server_hostname;
cp = hc->hs->hostname;
}
if (cp == NULL)
@ -3247,7 +3251,7 @@ static int really_check_referer(httpd_conn *hc)
#ifndef CONFIG_THTTPD_VHOST
/* Not vhosting, use the server name. */
lp = hs->server_hostname;
lp = hs->hostname;
if (!lp)
{
/* Couldn't figure out local hostname - give up. */
@ -3332,13 +3336,15 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
{
FAR httpd_server *hs;
nvdbg("cwd: %s\n", cwd);
/* Save the PID of the main thread */
main_thread = getpid();
/* Allocate the server structure */
hs = NEW(httpd_server, 1);
hs = (FAR httpd_server *)zalloc(sizeof(httpd_server));
if (!hs)
{
ndbg("out of memory allocating an httpd_server\n");
@ -3346,12 +3352,13 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
}
#ifdef CONFIG_THTTPD_HOSTNAME
hs->server_hostname = strdup(CONFIG_THTTPD_HOSTNAME);
hs->hostname = strdup(CONFIG_THTTPD_HOSTNAME);
#else
hs->server_hostname = strdup(httpd_ntoa(sa));
hs->hostname = strdup(httpd_ntoa(sa));
#endif
nvdbg("hostname: %s\n", hs->hostname);
if (!hs->server_hostname)
if (!hs->hostname)
{
ndbg("out of memory copying hostname\n");
return NULL;
@ -3370,10 +3377,12 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
hs->listen_fd = initialize_listen_socket(sa);
if (hs->listen_fd == -1)
{
ndbg("Failed to create listen socket\n");
free_httpd_server(hs);
return (httpd_server *) 0;
return NULL;
}
nvdbg("Calling init_mime()\n");
init_mime();
/* Done initializing. */

View File

@ -114,8 +114,7 @@ typedef struct sockaddr_in httpd_sockaddr;
typedef struct
{
char *binding_hostname;
char *server_hostname;
char *hostname;
int cgi_count;
char *cwd;
int listen_fd;

View File

@ -175,7 +175,7 @@ static void shut_down(void)
}
}
if (hs != (httpd_server *) 0)
if (hs)
{
httpd_server *ths = hs;
hs = (httpd_server *) 0;
@ -747,6 +747,8 @@ int thttpd_main(int argc, char **argv)
int ret;
#endif
nvdbg("THTTPD started\n");
/* Setup host address */
#ifdef CONFIG_NET_IPv6
@ -803,9 +805,11 @@ int thttpd_main(int argc, char **argv)
/* Initialize the HTTP layer */
nvdbg("Calling httpd_initialize()\n");
hs = httpd_initialize(&sa, cwd);
if (!hs)
{
ndbg("httpd_initialize() failed\n");
exit(1);
}
@ -870,6 +874,7 @@ int thttpd_main(int argc, char **argv)
/* Main loop */
nvdbg("Entering the main loop\n");
(void)gettimeofday(&tv, (struct timezone *)0);
while ((!terminate) || num_connects > 0)
{