9
0
Fork 0

Add framework for THTTPD example

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1989 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2009-07-18 19:47:08 +00:00
parent e93f39b93a
commit 3a434976d8
14 changed files with 306 additions and 60 deletions

View File

@ -820,3 +820,9 @@
when creating test threads (16Kb stacksize). The stack size should
be controlled by the .config file or the OSTest won't work on platforms
with memory constraints.
* netutils/thttpd: An initial port of Jef Poskanzer's THTTPD HTPPD server.
See http://acme.com/software/thttpd/.
* examples/thttpd: A basic test program for THTTPD
* configs/eagle100/thttpd: A build configuration for THTTPD on the Micromint
Eagle-100 LMS6918 (Cortex-M3) board.

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
<p>Last Updated: July 13, 2009</p>
<p>Last Updated: July 18, 2009</p>
</td>
</tr>
</table>
@ -1493,6 +1493,11 @@ nuttx-0.4.10 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
when creating test threads (16Kb stacksize). The stack size should
be controlled by the .config file or the OSTest won't work on platforms
with memory constraints.
* netutils/thttpd: An initial port of Jef Poskanzer's THTTPD HTPPD server.
See http://acme.com/software/thttpd/.
* examples/thttpd: A basic test program for THTTPD
* configs/eagle100/thttpd: A build configuration for THTTPD on the Micromint
Eagle-100 LMS6918 (Cortex-M3) board.
nuttx-0.4.10 2009-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -116,7 +116,7 @@ endif
# Add libraries for network support
ifeq ($(CONFIG_NET),y)
LINKLIBS += net/libnet$(LIBEXT) netutils/libnetutils$(LIBEXT) netutils/libthttpd$(LIBEXT)
LINKLIBS += net/libnet$(LIBEXT) netutils/libnetutils$(LIBEXT)
endif
# Add libraries for file system support
@ -226,9 +226,6 @@ net/libnet$(LIBEXT): context
netutils/libnetutils$(LIBEXT): context
@$(MAKE) -C netutils TOPDIR="$(TOPDIR)" libnetutils$(LIBEXT)
netutils/libthttpd$(LIBEXT): context
@$(MAKE) -C netutils TOPDIR="$(TOPDIR)" libthttpd$(LIBEXT)
fs/libfs$(LIBEXT): context
@$(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT)

View File

@ -254,7 +254,7 @@ CONFIG_HAVE_LIBM=n
# desciptors by task_create() when a new task is started. If
# set, all sockets will appear to be closed in the new task.
#
CONFIG_EXAMPLE=nxflat
CONFIG_EXAMPLE=thttpd
CONFIG_DEBUG=n
CONFIG_DEBUG_VERBOSE=n
CONFIG_DEBUG_NET=y
@ -556,6 +556,13 @@ CONFIG_THTTPD_TILDE_MAP2=n
CONFIG_THTTPD_GENERATE_INDICES=n
CONFIG_THTTPD_URLPATTERN=n
#
# Additional settings for examples/thttpd
#
CONFIG_EXAMPLE_THTTPD_NOMAC=n
CONFIG_EXAMPLE_THTTPD_DRIPADDR=(10<<24|0<<16|0<<8|1)
CONFIG_EXAMPLE_THTTPD_NETMASK=(255<<24|255<<16|255<<8|0)
#
# Settings for examples/uip
#

View File

@ -293,6 +293,17 @@ examples/serloop
Use C buffered I/O (getchar/putchar) vs. raw console I/O
(read/read).
examples/thttpd
^^^^^^^^^^^^^^^
An example that builds netutils/thttpd with some simple NXFLAT
CGI programs. see configs/README.txt for most THTTPD settings.
In addition to those, this example accepts:
CONFIG_EXAMPLE_THTTPD_NOMAC - (May be defined to use software assigned MAC)
CONFIG_EXAMPLE_THTTPD_DRIPADDR - Default router IP addess
CONFIG_EXAMPLE_THTTPD_NETMASK - Network mask
examples/udp
^^^^^^^^^^^^

View File

@ -0,0 +1,75 @@
############################################################################
# examples/thttpd/Makefile
#
# Copyright (C) 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = main.c
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
BIN = lib$(CONFIG_EXAMPLE)$(LIBEXT)
all: $(BIN)
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $@, $${obj}); \
done ; )
.depend: Makefile $(SRCS)
@$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f $(BIN) *~ .*.swp
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep

View File

@ -0,0 +1,135 @@
/****************************************************************************
* examples/thttpd/main.c
*
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <debug.h>
#include <net/if.h>
#include <net/uip/thttpd.h>
#include <net/uip/uip-arp.h>
#include <net/uip/uip-lib.h>
/****************************************************************************
* Definitions
****************************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS
# ifdef CONFIG_DEBUG
# define message(...) lib_lowprintf(__VA_ARGS__)
# else
# define message(...) printf(__VA_ARGS__)
# endif
#else
# ifdef CONFIG_DEBUG
# define message lib_lowprintf
# else
# define message (void)
# endif
#endif
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* user_initialize
****************************************************************************/
#ifndef CONFIG_HAVE_WEAKFUNCTIONS
void user_initialize(void)
{
/* Stub that must be provided only if the toolchain does not support weak
* functions.
*/
}
#endif
/****************************************************************************
* user_start
****************************************************************************/
int user_start(int argc, char *argv[])
{
struct in_addr addr;
#ifdef CONFIG_EXAMPLE_UIP_NOMAC
uint8 mac[IFHWADDRLEN];
#endif
char *thttpd_argv = "thttpd";
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLE_UIP_NOMAC
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0xb0;
mac[3] = 0x0b;
mac[4] = 0xba;
mac[5] = 0xbe;
uip_setmacaddr("eth0", mac);
#endif
/* Set up our host address */
addr.s_addr = HTONL(CONFIG_THTTPD_IPADDR);
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_THTTPD_DRIPADDR);
uip_setdraddr("eth0", &addr);
/* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLE_THTTPD_NETMASK);
uip_setnetmask("eth0", &addr);
printf("Starting THTTPD\n");
thttpd_main(1, &thttpd_argv);
return 0;
}

View File

@ -42,6 +42,7 @@ include smtp/Make.defs
include telnetd/Make.defs
include webclient/Make.defs
include webserver/Make.defs
include thttpd/Make.defs
endif
ifeq ($(CONFIG_NET_UDP),y)
include dhcpc/Make.defs
@ -53,16 +54,16 @@ endif
endif
endif
SUBDIRS = uiplib dhcpc dhcpd resolv smtp telnetd webclient webserver tftpc
SUBDIRS = uiplib dhcpc dhcpd resolv smtp telnetd webclient webserver tftpc thttpd
ASRCS = $(UIPLIB_ASRCS) $(DHCPC_ASRCS) $(DHCPD_ASRCS) $(RESOLV_ASRCS) \
$(SMTP_ASRCS) $(TELNETD_ASRCS) $(WEBCLIENT_ASRCS) $(WEBSERVER_ASRCS) \
$(TFTPC_ASRCS)
$(TFTPC_ASRCS) $(THTTPD_ASRCS)
AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = $(UIPLIB_CSRCS) $(DHCPC_CSRCS) $(DHCPD_CSRCS) $(RESOLV_CSRCS) \
$(SMTP_CSRCS) $(TELNETD_CSRCS) $(WEBCLIENT_CSRCS) $(WEBSERVER_CSRCS) \
$(TFTPC_CSRCS)
$(TFTPC_CSRCS) $(THTTPD_CSRCS)
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
@ -70,9 +71,9 @@ OBJS = $(AOBJS) $(COBJS)
BIN = libnetutils$(LIBEXT)
VPATH = uiplib:dhcpc:dhcpd:resolv:smtp:telnetd:webclient:webserver:tftpc
VPATH = uiplib:dhcpc:dhcpd:resolv:smtp:telnetd:webclient:webserver:tftpc:thttpd
all: $(BIN) libthttpd$(LIBEXT)
all: $(BIN)
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@ -85,17 +86,12 @@ $(BIN): $(OBJS)
$(call ARCHIVE, $@, $${obj}); \
done ; )
thttpd/libthttpd$(LIBEXT):
@$(MAKE) -C thttpd libthttpd$(LIBEXT) TOPDIR="$(TOPDIR)"
libthttpd$(LIBEXT): thttpd/libthttpd$(LIBEXT)
@cp -a thttpd/libthttpd$(LIBEXT) .
.depend: Makefile $(SRCS)
@$(MAKE) -C thttpd all TOPDIR="$(TOPDIR)"
ifeq ($(CONFIG_NET),y)
@$(MKDEP) --dep-path . --dep-path uiplib --dep-path dhcpc --dep-path dhcpd \
--dep-path smtp --dep-path webclient --dep-path resolv \
--dep-path telnetd --dep-path webserver --dep-path tftpc \
--dep-path smtp --dep-path webclient --dep-path resolv --dep-path telnetd \
--dep-path webserver --dep-path tftpc --dep-path thttpd \
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
endif
@touch $@
@ -104,7 +100,7 @@ depend: .depend
@$(MAKE) -C thttpd depend TOPDIR="$(TOPDIR)"
clean:
@rm -f $(BIN) libthttpd$(LIBEXT) *~ .*.swp
@rm -f $(BIN) *~ .*.swp
$(call CLEAN)
@( for dir in $(SUBDIRS); do \
rm -f $${dir}/*~ $${dir}/.*.swp; \

View File

@ -18,4 +18,7 @@ highly influenced by uIP) include:
dhcpd - Dynamic Host Configuration Protocol (DHCP) server
tftpc - TFTP client
thttpd - This is a port of Jef Poskanzer's THTTPD HTPPD server.
See http://acme.com/software/thttpd/.

View File

@ -0,0 +1,38 @@
############################################################################
# netutils/thttpd/Make.defs
#
# Copyright (C) 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
THTTPD_ASRCS =
THTTPD_CSRCS = thttpd.c libhttpd.c timers.c fdwatch.c tdate_parse.c

View File

@ -47,29 +47,8 @@ SUBDIR_BIN3 = ssi
SUBDIR_BIN += cgi-bin/$(SUBDIR_BIN1) cgi-bin/$(SUBDIR_BIN2) cgi-bin/$(SUBDIR_BIN3)
endif
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = thttpd.c libhttpd.c timers.c fdwatch.c tdate_parse.c
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
BIN = libthttpd$(LIBEXT)
all: $(BIN) $(SUBDIR_BIN)
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $@, $${obj}); \
done ; )
all: $(SUBDIR_BIN)
.PHONY: depend clean distclean
ifeq ($(CONFIG_NXFLAT),y)
cgi-bin:
@ -94,22 +73,15 @@ cgi-bin/$(SUBDIR_BIN3): cgi-bin cgi-src/$(SUBDIR_BIN3)
@cp -a cgi-src/$(SUBDIR_BIN3) $@
endif
.depend: Makefile $(SRCS)
@$(MKDEP) --dep-path . $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
depend:
clean:
@rm -f $(BIN) *~ .*.swp
@rm -f *~ .*.swp
@rm -rf cgi-bin
$(call CLEAN)
@( for dir in $(SUBDIRS); do \
rm -f $${dir}/*~ $${dir}/.*.swp; \
done ; )
@$(MAKE) -C cgi-src clean
distclean: clean
@rm -f Make.dep .depend
@$(MAKE) -C cgi-src distclean
-include Make.dep

View File

@ -63,7 +63,7 @@ int main(int argc, char *argv[])
{
fprintf(stderr, "phf CGI probe from %s\n", getenv("REMOTE_ADDR"));
(void)printf("\
(void)printf("\
Content-type: text/html\n\
Status: 404/html\n\
\n\
@ -73,7 +73,5 @@ The requested object does not exist on this server.\n\
The link you followed is either outdated, inaccurate,\n\
or the server has been instructed not to let you have it.\n\
</BODY></HTML>\n");
return 0;
}
return 1;
return 0;
}

View File

@ -869,7 +869,7 @@ static void read_file(FILE *instream, char *vfilename, char *filename)
break;
}
putcchar((char)ich);
putchar((char)ich);
}
}
@ -892,7 +892,7 @@ int main(int argc, char **argv)
/* The MIME type has to be text/html. */
(voidfputs("Content-type: text/html\n\n");
(void)puts("Content-type: text/html\n\n");
/* Get the name that we were run as. */

View File

@ -743,6 +743,9 @@ int thttpd_main(int argc, char **argv)
struct sockaddr_in sa;
#endif
struct timeval tv;
#ifdef CONFIG_THTTPD_DIR
int ret;
#endif
/* Setup host address */