libthttpd.c now longer used fork() and execve()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1980 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
29899e1069
commit
1235ab92c5
102
include/net/uip/thttpd.h
Normal file
102
include/net/uip/thttpd.h
Normal file
@ -0,0 +1,102 @@
|
||||
/****************************************************************************
|
||||
* net/uip/thttpd.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __NET_UIP_THTTPD_H
|
||||
#define __NET_UIP_THTTPD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* These values must be provided by the user before the THTTPD task daemon
|
||||
* is started:
|
||||
*
|
||||
* g_thttpdsymtab: A symbol table describing all of the symbols exported
|
||||
* from the base system. These symbols are used to bind address references
|
||||
* in CGI programs to NuttX.
|
||||
* g_nsymbols: The number of symbols in g_thttpdsymtab[].
|
||||
*
|
||||
* (See examples/nxflat and examples/thttpd for examples of how such a symbol
|
||||
* table may be created.)
|
||||
*/
|
||||
|
||||
EXTERN FAR const struct symtab_s *g_thttpdsymtab;
|
||||
EXTERN int g_thttpdnsymbols;
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: thttpd_main
|
||||
*
|
||||
* Description:
|
||||
* This function is the entrypoint into the THTTPD server. It does not
|
||||
* return. It may be called, the normal mechanism for starting the server
|
||||
* is:
|
||||
*
|
||||
* 1) Set is g_thttpdsymtab and g_thttpdnsymbols. The user is required
|
||||
* to provide a symbol table to use for binding CGI programs (if CGI
|
||||
* is enabled. See examples/nxflat and examples/thttpd for examples of
|
||||
* how such a symbol table may be created.)
|
||||
* 2) Call task_create() to start thttpd_main()
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int thttpd_main(int argc, char **argv);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NET_UIP_THTTPD_H */
|
@ -43,7 +43,8 @@
|
||||
/* Make sure that the system is configured to handle THTTPD */
|
||||
|
||||
#undef CONFIG_THTTPD
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) && defined(CONFIG_NET_TCPBACKLOG)
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) && \
|
||||
defined(CONFIG_NET_TCPBACKLOG) && !defined(CONFIG_DISABLE_ENVIRONMENT)
|
||||
# define CONFIG_THTTPD
|
||||
#else
|
||||
# warning "THTTPD not built because dependenciesnot selected in configuration"
|
||||
@ -96,6 +97,16 @@
|
||||
# define CONFIG_THTTPD_CGI_PATTERN "/cgi-bin/*"
|
||||
#endif
|
||||
|
||||
/* These provide the priority and stack size of the CGI child tasks */
|
||||
|
||||
#ifndef CONFIG_THTTPD_CGI_PRIORITY
|
||||
# define CONFIG_THTTPD_CGI_PRIORITY 50
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_THTTPD_CGI_STACKSIZE
|
||||
# define CONFIG_THTTPD_CGI_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
/* Byte output limit for CGI tasks */
|
||||
|
||||
#ifndef CONFIG_THTTPD_CGI_BYTECOUNT
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -192,15 +192,15 @@ typedef struct
|
||||
* Return (httpd_server*) 0 on error.
|
||||
*/
|
||||
|
||||
extern httpd_server *httpd_initialize(httpd_sockaddr *sa, char *cwd);
|
||||
extern FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd);
|
||||
|
||||
/* Call to unlisten/close socket(s) listening for new connections. */
|
||||
|
||||
extern void httpd_unlisten(httpd_server * hs);
|
||||
extern void httpd_unlisten(httpd_server *hs);
|
||||
|
||||
/* Call to shut down. */
|
||||
|
||||
extern void httpd_terminate(httpd_server * hs);
|
||||
extern void httpd_terminate(httpd_server *hs);
|
||||
|
||||
/* When a listen fd is ready to read, call this. It does the accept() and
|
||||
* returns an httpd_conn* which includes the fd to read the request from and
|
||||
@ -212,7 +212,7 @@ extern void httpd_terminate(httpd_server * hs);
|
||||
* first call using each different httpd_conn.
|
||||
*/
|
||||
|
||||
extern int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn * hc);
|
||||
extern int httpd_get_conn(httpd_server *hs, int listen_fd, httpd_conn *hc);
|
||||
|
||||
/* Checks whether the data in hc->read_buf constitutes a complete request
|
||||
* yet. The caller reads data into hc->read_buf[hc->read_idx] and advances
|
||||
@ -222,7 +222,7 @@ extern int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn * hc);
|
||||
* complete request, or there won't be a valid request due to a syntax error.
|
||||
*/
|
||||
|
||||
extern int httpd_got_request(httpd_conn * hc);
|
||||
extern int httpd_got_request(httpd_conn *hc);
|
||||
|
||||
/* Parses the request in hc->read_buf. Fills in lots of fields in hc,
|
||||
* like the URL and the various headers.
|
||||
@ -230,7 +230,7 @@ extern int httpd_got_request(httpd_conn * hc);
|
||||
* Returns -1 on error.
|
||||
*/
|
||||
|
||||
extern int httpd_parse_request(httpd_conn * hc);
|
||||
extern int httpd_parse_request(httpd_conn *hc);
|
||||
|
||||
/* Starts sending data back to the client. In some cases (directories,
|
||||
* CGI programs), finishes sending by itself - in those cases, hc->file_fd
|
||||
@ -241,29 +241,27 @@ extern int httpd_parse_request(httpd_conn * hc);
|
||||
* Returns -1 on error.
|
||||
*/
|
||||
|
||||
extern int httpd_start_request(httpd_conn * hc, struct timeval *nowP);
|
||||
extern int httpd_start_request(httpd_conn *hc, struct timeval *nowP);
|
||||
|
||||
/* Actually sends any buffered response text. */
|
||||
|
||||
extern void httpd_write_response(httpd_conn * hc);
|
||||
extern void httpd_write_response(httpd_conn *hc);
|
||||
|
||||
/* Call this to close down a connection and free the data. A fine point,
|
||||
* if you fork() with a connection open you should still call this in the
|
||||
* parent process - the connection will stay open in the child.
|
||||
/* Call this to close down a connection and free the data.
|
||||
* If you don't have a current timeval handy just pass in 0.
|
||||
*/
|
||||
|
||||
extern void httpd_close_conn(httpd_conn * hc, struct timeval *nowP);
|
||||
extern void httpd_close_conn(httpd_conn *hc, struct timeval *nowP);
|
||||
|
||||
/* Call this to de-initialize a connection struct and *really* free the
|
||||
* mallocced strings.
|
||||
*/
|
||||
|
||||
extern void httpd_destroy_conn(httpd_conn * hc);
|
||||
extern void httpd_destroy_conn(httpd_conn *hc);
|
||||
|
||||
/* Send an error message back to the client. */
|
||||
|
||||
extern void httpd_send_err(httpd_conn * hc, int status, char *title,
|
||||
extern void httpd_send_err(httpd_conn *hc, int status, char *title,
|
||||
char *extraheads, char *form, char *arg);
|
||||
|
||||
/* Some error messages. */
|
||||
@ -281,7 +279,7 @@ extern char *httpd_method_str(int method);
|
||||
|
||||
/* Reallocate a string. */
|
||||
|
||||
extern void httpd_realloc_str(char **strP, size_t * maxsizeP, size_t size);
|
||||
extern void httpd_realloc_str(char **strP, size_t *maxsizeP, size_t size);
|
||||
|
||||
/* Format a network socket to a string representation. */
|
||||
|
||||
|
@ -53,6 +53,8 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/compiler.h>
|
||||
#include <nuttx/symtab.h>
|
||||
#include <net/uip/thttpd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "fdwatch.h"
|
||||
@ -709,13 +711,29 @@ static void thttpd_logstats(long secs)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: thttpd_main
|
||||
*
|
||||
* Description:
|
||||
* This function is the entrypoint into the THTTPD server. It does not
|
||||
* return. It may be called, the normal mechanism for starting the server
|
||||
* is:
|
||||
*
|
||||
* 1) Set is g_thttpdsymtab and g_thttpdnsymbols. The user is required
|
||||
* to provide a symbol table to use for binding CGI programs (if CGI
|
||||
* is enabled. See examples/nxflat and examples/thttpd for examples of
|
||||
* how such a symbol table may be created.
|
||||
* 2) Call task_create() to start thttpd_main()
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int thttpd_main(int argc, char **argv)
|
||||
{
|
||||
char cwd[MAXPATHLEN + 1];
|
||||
int num_ready;
|
||||
int cnum;
|
||||
struct connect_s *conn;
|
||||
httpd_conn *hc;
|
||||
FAR struct connect_s *conn;
|
||||
FAR httpd_conn *hc;
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
struct sockaddr_in6 sa;
|
||||
#else
|
||||
@ -726,7 +744,7 @@ int thttpd_main(int argc, char **argv)
|
||||
/* Setup host address */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
# error "IPv6 support not yet implemented"
|
||||
# error "IPv6 support not yet implemented"
|
||||
#else
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_port = HTONS(CONFIG_THTTPD_PORT);
|
||||
|
Loading…
x
Reference in New Issue
Block a user