/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
* Simon Goldschmidt
*
*//* This httpd supports for a
* rudimentary server-side-include facility which will replace tags of the form
* <!--#tag--> in any file whose extension is .shtml, .shtm or .ssi with
* strings provided by an include handler whose pointer is provided to the
* module via function http_set_ssi_handler().
* Additionally, a simple common
* gateway interface (CGI) handling mechanism has been added to allow clients
* to hook functions to particular request URIs.
*
* To enable SSI support, define label LWIP_HTTPD_SSI in lwipopts.h.
* To enable CGI support, define label LWIP_HTTPD_CGI in lwipopts.h.
*
* By default, the server assumes that HTTP headers are already present in
* each file stored in the file system. By defining LWIP_HTTPD_DYNAMIC_HEADERS in
* lwipopts.h, this behavior can be changed such that the server inserts the
* headers automatically based on the extension of the file being served. If
* this mode is used, be careful to ensure that the file system image used
* does not already contain the header information.
*
* File system images without headers can be created using the makefsfile
* tool with the -h command line option.
*
*
* Notes about valid SSI tags
* --------------------------
*
* The following assumptions are made about tags used in SSI markers:
*
* 1. No tag may contain '-' or whitespace characters within the tag name.
* 2. Whitespace is allowed between the tag leadin "<!--#" and the start of
* the tag name and between the tag name and the leadout string "-->".
* 3. The maximum tag name length is LWIP_HTTPD_MAX_TAG_NAME_LEN, currently 8 characters.
*
* Notes on CGI usage
* ------------------
*
* The simple CGI support offered here works with GET method requests only
* and can handle up to 16 parameters encoded into the URI. The handler
* function may not write directly to the HTTP output but must return a
* filename that the HTTP server will send to the browser as a response to
* the incoming CGI request.
*
*
*
* The list of supported file types is quite short, so if makefsdata complains
* about an unknown extension, make sure to add it (and its doctype) to
* the 'g_psHTTPHeaders' list.
*/#include"httpd.h"#include"lwip/debug.h"#include"lwip/stats.h"#include"httpd_structs.h"#include"lwip/tcp.h"#include"fs.h"#include<string.h>#include<stdlib.h>#if LWIP_TCP#ifndef HTTPD_DEBUG#define HTTPD_DEBUG LWIP_DBG_OFF#endif/** Set this to 1, set