Nut/OS  5.0.5
API Reference
httpd.c File Reference

HTTP server support routines. More...

#include <cfg/arch.h>
#include <cfg/http.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <ctype.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <memdebug.h>
#include <sys/heap.h>
#include <sys/version.h>
#include <pro/rfctime.h>
#include <pro/httpd.h>
#include "dencode.h"
#include "httpd_p.h"
Include dependency graph for httpd.c:

Data Structures

struct  _REQUEST_LOOKUP
 Structure for table of interpreted header names. More...

Defines

#define HTTP_MAJOR_VERSION   1
 Local major HTTP version.
#define HTTP_MINOR_VERSION   1
 Local minor HTTP version.
#define HTTP_KEEP_ALIVE_REQ   0
 Maximum number of requests per connection.
#define HTTP_MAX_REQUEST_SIZE   256
 Maximum size of an incoming request line.
#define HTTP_FILE_CHUNK_SIZE   512
 Chunk size while sending files.
#define HTTPD_SUPPORT_GZIP   0
 Enable GZIP support.
#define NUM_REQUEST_LOOKUP   sizeof(req_lookup) / sizeof(REQUEST_LOOKUP)
 Number of entries in the header name table.
#define MAX_REQUEST_NAME_SIZE   17
 Size of the largest entry in the header name table.
#define GZIP_ID   0x8b1f

Typedefs

typedef struct _REQUEST_LOOKUP REQUEST_LOOKUP
 Structure for table of interpreted header names.

Functions

void NutHttpSendHeaderTop (FILE *stream, REQUEST *req, int status, char *title)
 Send top lines of a standard HTML header.
void NutHttpSendHeaderBot (FILE *stream, char *mime_type, long bytes)
 Send bottom lines of a standard HTML header.
void NutHttpSendHeaderBottom (FILE *stream, REQUEST *req, char *mime_type, long bytes)
 Send bottom lines of a standard HTML header.
void NutHttpSendError (FILE *stream, REQUEST *req, int status)
 Send a HTTP error response.
char * NutGetMimeType (char *name)
 Return the mime type description of a specified file name.
void * NutGetMimeHandler (char *name)
 Return the mime type handler of a specified file name.
void NutHttpURLDecode (char *str)
 URLDecodes a string.
void NutHttpProcessQueryString (REQUEST *req)
 Parses the QueryString.
int NutRegisterHttpRoot (char *path)
 Register the HTTP server's root directory.
void NutHttpSetOptionFlags (uint32_t flags)
 Set HTTP option flags.
uint32_t NutHttpGetOptionFlags (void)
 Retrieve HTTP option flags.
void NutHttpProcessRequest (FILE *stream)
 Process the next HTTP request.

Variables

MIMETYPES mimeTypes []
 Known mime types.

Detailed Description

HTTP server support routines.

 *
 * $Log$
 * Revision 1.26  2009/02/13 14:52:05  haraldkipp
 * Include memdebug.h for heap management debugging support.
 *
 * Revision 1.25  2009/02/06 15:40:29  haraldkipp
 * Using newly available strdup() and calloc().
 * Replaced NutHeap routines by standard malloc/free.
 * Replaced pointer value 0 by NULL.
 *
 * Revision 1.24  2008/08/11 07:00:35  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.23  2008/07/17 11:36:32  olereinhardt
 * - Moved some functions used in httpd.c as well as in ssi.c into httpd_p.c
 * - Implemeted $QUERY_STRING parameter in for CGIs included by a ssi file
 *
 * Revision 1.22  2008/07/14 13:11:15  haraldkipp
 * Added file length check to avoid loading directories when using PHAT.
 *
 * Revision 1.21  2008/07/10 12:09:39  haraldkipp
 * Wrong mime type was returned for default files within subdirectories.
 * Put duplicate code in a new static function GetMimeEntry.
 *
 * Revision 1.20  2008/07/08 13:27:55  haraldkipp
 * Several HTTP server options are now configurable.
 * Keepalive is now disabled by default to maintain backward compatibility.
 *
 * Revision 1.19  2008/05/21 14:10:19  thiagocorrea
 * Workaround HTTP stall connections. Details in bug id 1968754
 *
 * Revision 1.18  2008/05/16 03:38:27  thiagocorrea
 * Revert httpd memory allocation calls to NutHeapAlloc for consistency and
 * move DestroyRequestInfo to a shared file (reduces code size and remove duplicates
 * from httpd.c and ssi.c)
 *
 * Revision 1.17  2008/04/15 05:13:30  hwmaier
 * Fixed compilation error with avr-gcc 3.4.6
 *
 * Revision 1.16  2008/04/01 10:11:35  haraldkipp
 * Added the new, enhanced httpd API library.
 * Bugs #1839026 and #1839029 fixed.
 *
 * Revision 1.15  2006/11/08 08:52:31  haraldkipp
 * Bugfix, kindly provided by Steve Venroy. Already released request
 * structure was passed to NutHttpSendError().
 *
 * Revision 1.14  2006/10/08 16:48:22  haraldkipp
 * Documentation fixed
 *
 * Revision 1.13  2006/03/16 15:25:38  haraldkipp
 * Changed human readable strings from u_char to char to stop GCC 4 from
 * nagging about signedness.
 *
 * Revision 1.12  2006/01/06 09:19:42  haraldkipp
 * NutHttpURLEncode() no longer encodes everything that isn't alphanumeric.
 * See RFC2396. Thanks to Lloyd Bailey for this update.
 *
 * Revision 1.11  2005/10/24 11:02:28  haraldkipp
 * Integer division hack for ARM without CRT removed.
 *
 * Revision 1.10  2005/08/26 14:12:39  olereinhardt
 * Added NutHttpProcessPostQuery(FILE *stream, REQUEST * req)
 *
 * Revision 1.9  2005/08/05 11:23:11  olereinhardt
 * Added support to register a custom handler for mime types.
 * Added Server side include support and ASP support.
 *
 * Revision 1.8  2005/04/30 13:08:15  chaac
 * Added support for parsing Content-Length field in HTTP requests.
 *
 * Revision 1.7  2005/04/05 17:58:02  haraldkipp
 * Avoid integer division on ARM platform as long as we run without crtlib.
 *
 * Revision 1.6  2004/12/16 10:17:18  haraldkipp
 * Added Mikael Adolfsson's excellent parameter parsing routines.
 *
 * Revision 1.5  2004/07/30 19:45:48  drsung
 * Slightly improved handling if socket was closed by peer.
 *
 * Revision 1.4  2004/03/02 10:09:59  drsung
 * Small bugfix in NutHttpSendError. Thanks to Damian Slee.
 *
 * Revision 1.3  2003/07/20 16:03:27  haraldkipp
 * Saved some RAM by moving string literals to program memory.
 *
 * Revision 1.2  2003/07/17 12:28:21  haraldkipp
 * Memory hole bugfix
 *
 * Revision 1.1.1.1  2003/05/09 14:41:58  haraldkipp
 * Initial using 3.2.1
 *
 * Revision 1.14  2003/02/04 18:17:32  harald
 * Version 3 released
 *
 * Revision 1.13  2003/01/14 17:04:20  harald
 * Using FAT file system and added types
 *
 * Revision 1.12  2002/10/31 16:32:45  harald
 * Mods by troth for Linux
 *
 * Revision 1.11  2002/09/15 17:08:44  harald
 * Allow different character sets
 *
 * Revision 1.10  2002/06/26 17:29:49  harald
 * First pre-release with 2.4 stack
 *
 * 

Define Documentation

#define HTTP_MAJOR_VERSION   1

Local major HTTP version.

Referenced by NutHttpSendHeaderTop().

#define HTTP_MINOR_VERSION   1

Local minor HTTP version.

Referenced by NutHttpSendHeaderTop().

#define HTTP_KEEP_ALIVE_REQ   0

Maximum number of requests per connection.

Referenced by NutHttpProcessRequest().

#define HTTP_MAX_REQUEST_SIZE   256

Maximum size of an incoming request line.

Referenced by NutHttpProcessRequest().

#define HTTP_FILE_CHUNK_SIZE   512

Chunk size while sending files.

#define HTTPD_SUPPORT_GZIP   0

Enable GZIP support.

#define GZIP_ID   0x8b1f

Referenced by HttpSendHeaderBottom().