diff options
Diffstat (limited to 'apps/include/netutils')
-rw-r--r-- | apps/include/netutils/httpd.h | 120 |
1 files changed, 116 insertions, 4 deletions
diff --git a/apps/include/netutils/httpd.h b/apps/include/netutils/httpd.h index 7cd002b66..46a32bd62 100644 --- a/apps/include/netutils/httpd.h +++ b/apps/include/netutils/httpd.h @@ -1,7 +1,7 @@ /**************************************************************************** * apps/include/netutils/httpd.h * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Based on uIP which also has a BSD style license: @@ -44,19 +44,131 @@ * Included Files ****************************************************************************/ +#include <nuttx/net/uip/uip.h> + /**************************************************************************** - * Public Function Prototypes + * Pre-processor Definitions ****************************************************************************/ #ifdef __cplusplus -#define EXTERN extern "C" +# define EXTERN extern "C" extern "C" { #else -#define EXTERN extern +# define EXTERN extern +#endif + +/* As threads are created to handle each request, a stack must be allocated + * for the thread. Use a default if the user provided no stacksize. + */ + +#ifndef CONFIG_NETUTILS_HTTPDSTACKSIZE +# define CONFIG_NETUTILS_HTTPDSTACKSIZE 4096 +#endif + +#ifndef CONFIG_NETUTILS_HTTPDFSSTATS +# define CONFIG_NETUTILS_HTTPDFSSTATS +#endif + +#ifndef CONFIG_NETUTILS_HTTPDFILESTATS +# define CONFIG_NETUTILS_HTTPDFILESTATS #endif +#ifndef CONFIG_NET_STATISTICS +# undef CONFIG_NETUTILS_HTTPDNETSTATS +#endif + +/* For efficiency reasons, the size of the IO buffer should be a multiple + * of the TCP MSS value. Also, the current design requires that the IO + * buffer be sufficiently large to contain the entire GET request. + */ + +#define HTTPD_IOBUFFER_SIZE (3*UIP_TCP_MSS) + +/* this is the maximum size of a file path */ + +#define HTTPD_MAX_FILENAME 20 + +/**************************************************************************** + * Public types + ****************************************************************************/ + +struct httpd_fs_file +{ + char *data; + int len; +}; + +struct httpd_state +{ + char ht_buffer[HTTPD_IOBUFFER_SIZE]; /* recv()/send() buffer */ + char ht_filename[HTTPD_MAX_FILENAME]; /* filename from GET command */ + struct httpd_fs_file ht_file; /* Fake file data to send */ + int ht_sockfd; /* The socket descriptor from accept() */ + char *ht_scriptptr; + uint16_t ht_scriptlen; + uint16_t ht_sndlen; +}; + +struct httpd_fsdata_file +{ + const struct httpd_fsdata_file *next; + FAR const uint8_t *name; + FAR const uint8_t *data; + int len; +#ifdef CONFIG_NETUTILS_HTTPDFSSTATS + uint16_t count; +#endif +}; + +struct httpd_fsdata_file_noconst +{ + FAR struct httpd_fsdata_file *next; + FAR char *name; + FAR char *data; + int len; +#ifdef CONFIG_NETUTILS_HTTPDFSSTATS + uint16_t count; +#endif +}; + +typedef void (*httpd_cgifunction)(struct httpd_state *, char *); + +struct httpd_cgi_call +{ + struct httpd_cgi_call *next; + const char *name; + httpd_cgifunction function; +}; + +/* HTTPD CGI function declaration + * + * Description: + * This macro is used for declaring a HTTPD CGI function. This function is + * then added to the list of HTTPD CGI functions with the httpd_cgi_register() + * function. + + * Input Paramters: + * + * name The C variable name of the function + * str The string name of the function, used in the script file + * function A pointer to the function that implements it + */ + +#define HTTPD_CGI_CALL(name, str, function) \ +static void function(struct httpd_state *, char *); \ +static struct httpd_cgi_call name = {NULL, str, function} + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + EXTERN void httpd_init(void); EXTERN int httpd_listen(void); +EXTERN void httpd_cgi_register(struct httpd_cgi_call *cgi_call); +EXTERN uint16_t httpd_fs_count(char *name); + +EXTERN const struct httpd_fsdata_file g_httpdfs_root[]; +EXTERN const int g_httpd_numfiles; #undef EXTERN #ifdef __cplusplus |