AVR corrections from Richard Cochran; uIP webserver enhancements from Kate

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5126 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-09-11 13:19:59 +00:00
parent c7a2544230
commit de7764b1d4
10 changed files with 210 additions and 14 deletions

View File

@ -316,4 +316,6 @@
(submiteed by Kate). (submiteed by Kate).
* apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap() * apps/netutils/webserver/httpd_mmap.c: Fix errors when the mmap()
length is zero (submitted by Kate). length is zero (submitted by Kate).
* apps/netutils/webserver/httpd_sendfile.c: Add and option,
CONFIG_NETUTILS_HTTPD_SENDFILE to transfer files using the NuttX
sendfile() interface.

View File

@ -15,7 +15,8 @@ if NETUTILS_WEBSERVER
config NETUTILS_HTTPD_SCRIPT_DISABLE config NETUTILS_HTTPD_SCRIPT_DISABLE
bool "Disable %! scripting" bool "Disable %! scripting"
default n default y if NETUTILS_HTTPD_SENDFILE
default n if !NETUTILS_HTTPD_SENDFILE
---help--- ---help---
This option, if selected, will elide the %! scripting This option, if selected, will elide the %! scripting
@ -52,10 +53,40 @@ config NETUTILS_HTTPD_SERVERHEADER_DISABLE
---help--- ---help---
This option, if selected, will elide the Server\: header This option, if selected, will elide the Server\: header
choice
prompt "File Transfer Method"
default NETUTILS_HTTPD_CLASSIC
config NETUTILS_HTTPD_CLASSIC
bool "Pre-processed files"
---help---
Traditionally, the uIP-based webserver only sends "files" that have
been prepared as a data structure using nutts/tools/mkfsdata.pl
config NETUTILS_HTTPD_MMAP config NETUTILS_HTTPD_MMAP
bool "File mmap-ing" bool "File mmap-ing"
default n
---help--- ---help---
Replaces standard uIP server file open operations with mmap-ing operations. Traditionally, the uIP-based webserver only sends "files" that have
been prepared as a data structure using nutts/tools/mkfsdata.pl
However, extensions have been contributed. If this option is
selected, then files can be accessed from the NuttX file system
as well. This selection will map the files into memory (using mmap)
so that the logic is still basically compatible with the classic
approach.
config NETUTILS_HTTPD_MMAP
bool "sendfile()"
select NETUTILS_HTTPD_SCRIPT_DISABLE
---help---
Traditionally, the uIP-based webserver only sends "files" that have
been prepared as a data structure using nutts/tools/mkfsdata.pl
However, extensions have been contributed. If this option is
selected, then files can be accessed from the NuttX file system
as well. This selection will use the NuttX sendfile() interface
to send files. NOTE: if this option is selected, then scripting
must be disabled.
endchoice
endif endif

View File

@ -44,7 +44,9 @@ CSRCS =
ifeq ($(CONFIG_NET_TCP),y) ifeq ($(CONFIG_NET_TCP),y)
CSRCS = httpd.c httpd_cgi.c CSRCS = httpd.c httpd_cgi.c
ifeq ($(CONFIG_NETUTILS_HTTPD_MMAP),y) ifeq ($(CONFIG_NETUTILS_HTTPD_SENDFILE),y)
CSRCS += httpd_sendfile.c
else ifeq ($(CONFIG_NETUTILS_HTTPD_MMAP),y)
CSRCS += httpd_mmap.c CSRCS += httpd_mmap.c
else else
CSRCS += httpd_fs.c CSRCS += httpd_fs.c

View File

@ -69,6 +69,14 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#if !defined(CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE) && defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
# error "Script support and CONFIG_NETUTILS_HTTPD_SENDFILE are mutually exclusive"
#endif
#if defined(CONFIG_NETUTILS_HTTPD_SENDFILE) && defined(CONFIG_NETUTILS_HTTPD_MMAP)
# error "CONFIG_NETUTILS_HTTPD_SENDFILE and CONFIG_NETUTILS_HTTPD_MMAP are mutually exclusive"
#endif
#define ISO_nl 0x0a #define ISO_nl 0x0a
#define ISO_space 0x20 #define ISO_space 0x20
#define ISO_bang 0x21 #define ISO_bang 0x21
@ -131,7 +139,9 @@ static const char g_httpheader404[] =
static int httpd_open(const char *name, struct httpd_fs_file *file) static int httpd_open(const char *name, struct httpd_fs_file *file)
{ {
#ifdef CONFIG_NETUTILS_HTTPD_MMAP #if defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
return httpd_sendfile_open(name, file);
#elif defined(CONFIG_NETUTILS_HTTPD_MMAP)
return httpd_mmap_open(name, file); return httpd_mmap_open(name, file);
#else #else
return httpd_fs_open(name, file); return httpd_fs_open(name, file);
@ -140,7 +150,9 @@ static int httpd_open(const char *name, struct httpd_fs_file *file)
static int httpd_close(struct httpd_fs_file *file) static int httpd_close(struct httpd_fs_file *file)
{ {
#ifdef CONFIG_NETUTILS_HTTPD_MMAP #if defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
return httpd_sendfile_close(file);
#elif defined(CONFIG_NETUTILS_HTTPD_MMAP)
return httpd_mmap_close(file); return httpd_mmap_close(file);
#else #else
return OK; return OK;
@ -424,7 +436,11 @@ static int httpd_sendfile(struct httpd_state *pstate)
if (send_headers(pstate, g_httpheader404, strlen(g_httpheader404)) == OK) if (send_headers(pstate, g_httpheader404, strlen(g_httpheader404)) == OK)
{ {
#ifdef CONFIG_NETUTILS_HTTPD_SENDFILE
ret = httpd_sendfile_send(pstate->ht_sockfd, &pstate->ht_file);
#else
ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len); ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len);
#endif
} }
} }
else else
@ -447,7 +463,11 @@ static int httpd_sendfile(struct httpd_state *pstate)
else else
#endif #endif
{ {
#ifdef CONFIG_NETUTILS_HTTPD_SENDFILE
ret = httpd_sendfile_send(pstate->ht_sockfd, &pstate->ht_file);
#else
ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len); ret = httpd_addchunk(pstate, pstate->ht_file.data, pstate->ht_file.len);
#endif
} }
} }
} }
@ -603,7 +623,7 @@ int httpd_listen(void)
void httpd_init(void) void httpd_init(void)
{ {
#ifndef CONFIG_NETUTILS_HTTPD_MMAP #if !defined(CONFIG_NETUTILS_HTTPD_MMAP) && !defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
httpd_fs_init(); httpd_fs_init();
#endif #endif
} }

View File

@ -58,12 +58,22 @@
/* 'file' must be allocated by caller and will be filled in by the function. */ /* 'file' must be allocated by caller and will be filled in by the function. */
#if defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
int httpd_sendfile_open(const char *name, struct httpd_fs_file *file);
int httpd_sendfile_close(struct httpd_fs_file *file);
int httpd_sendfile_send(int outfd, struct httpd_fs_file *file);
#elif defined(CONFIG_NETUTILS_HTTPD_MMAP)
int httpd_mmap_open(const char *name, struct httpd_fs_file *file);
int httpd_mmap_close(struct httpd_fs_file *file);
#else
int httpd_fs_open(const char *name, struct httpd_fs_file *file); int httpd_fs_open(const char *name, struct httpd_fs_file *file);
void httpd_fs_init(void); void httpd_fs_init(void);
#ifdef CONFIG_NETUTILS_HTTPD_MMAP
int httpd_mmap_open(const char *name, struct httpd_fs_file *file);
int httpd_mmap_close(struct httpd_fs_file *file);
#endif #endif
#endif /* _NETUTILS_WEBSERVER_HTTPD_H */ #endif /* _NETUTILS_WEBSERVER_HTTPD_H */

View File

@ -0,0 +1,128 @@
/****************************************************************************
* netutils/webserver/httpd_mmap.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Header Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sendfile.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#include <apps/netutils/httpd.h>
#include "httpd.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
int httpd_sendfile_open(const char *name, struct httpd_fs_file *file)
{
char path[PATH_MAX];
struct stat st;
if (sizeof path < snprintf(path, sizeof path, "%s%s",
CONFIG_NETUTILS_HTTPD_PATH, name))
{
errno = ENAMETOOLONG;
return ERROR;
}
/* XXX: awaiting fstat to avoid a race */
if (-1 == stat(path, &st))
{
return ERROR;
}
if (st.st_size > INT_MAX || st.st_size > SIZE_MAX)
{
errno = EFBIG;
return ERROR;
}
file->len = (int) st.st_size;
file->fd = open(path, O_RDONLY);
if (file->fd == -1)
{
return ERROR;
}
return OK;
}
int httpd_sendfile_close(struct httpd_fs_file *file)
{
if (-1 == close(file->fd))
{
return ERROR;
}
return OK;
}
int httpd_sendfile_send(int outfd, struct httpd_fs_file *file)
{
if (-1 == sendfile(outfd, file->fd, 0, file->len))
{
return ERROR;
}
return OK;
}

View File

@ -3307,4 +3307,6 @@
(Noted by Ronen Vainish). (Noted by Ronen Vainish).
* fs/mmap/fs_rammap.c: Fix logic error and errno check (contributed * fs/mmap/fs_rammap.c: Fix logic error and errno check (contributed
by Kate). by Kate).
* arch/avr/src: Fixes from AVR32 build errors that have crept in
over the time; incorporated Kconfig for AVR3 (Richard Cochran).

View File

@ -40,8 +40,7 @@
ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src
ifeq ($(CONFIG_ARCH_AVR32),y) ifeq ($(CONFIG_ARCH_AVR32),y)
ARCH_SUBDIR = avr32 ARCH_SUBDIR = avr32
endif else ifeq ($(CONFIG_ARCH_AVR),y)
ifeq ($(CONFIG_ARCH_AVR),y)
ARCH_SUBDIR = avr ARCH_SUBDIR = avr
endif endif

View File

@ -69,7 +69,7 @@
* structure. If is non-NULL only during interrupt processing. * structure. If is non-NULL only during interrupt processing.
*/ */
extern volatile uint32_ *current_regs; extern volatile uint32_t *current_regs;
/* This is the beginning of heap as provided from up_head.S. This is the first /* This is the beginning of heap as provided from up_head.S. This is the first
* address in DRAM after the loaded program+bss+idle stack. The end of the * address in DRAM after the loaded program+bss+idle stack. The end of the

View File

@ -41,6 +41,8 @@
#include <stdint.h> #include <stdint.h>
#include <arch/avr32/irq.h>
#include "up_internal.h" #include "up_internal.h"
/**************************************************************************** /****************************************************************************