mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
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:
@@ -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
|
||||
|
||||
+464
-414
File diff suppressed because it is too large
Load Diff
+13
-15
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user