diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-31 23:05:51 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-31 23:05:51 +0000 |
commit | b351b752486c1693392faed106a8a77609006656 (patch) | |
tree | 8b04048671d38afda5fd5fbcea2ae16a9da8bcbc /apps/include/netutils/httpd.h | |
parent | f8d292453df82fde56d2e4674ba78b5885fed899 (diff) | |
download | nuttx-b351b752486c1693392faed106a8a77609006656.tar.gz nuttx-b351b752486c1693392faed106a8a77609006656.tar.bz2 nuttx-b351b752486c1693392faed106a8a77609006656.zip |
The content for uIP web server demo is no longer canned, but is not built dynameically (Thanks to Max Holtzberg)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5073 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/include/netutils/httpd.h')
-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 |