/*
* 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 <[email protected]>
*
*/
/* 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.
*
* @todo:
* - don't use mem_malloc() (for SSI/dynamic headers)
* - split too long functions into multiple smaller functions?
* - support more file types?
*/
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "httpd.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 and add the next line to lwippools.h to use a memp pool
* for allocating struct http_state instead of the heap:
*
* LWIP_MEMPOOL(HTTPD_STATE, 20, 100, "HTTPD_STATE")
*/
#ifndef HTTPD_USE_MEM_POOL
#define HTTPD_USE_MEM_POOL 0
#endif
/** The server port for HTTPD to use */
#ifndef HTTPD_SERVER_PORT
#define HTTPD_SERVER_PORT 80
#endif
/** Maximum retries before the connection is aborted/closed.
* - number of times pcb->poll is called -> default is 4*500ms = 2s;
* - reset when pcb->sent is called
*/
#ifndef HTTPD_MAX_RETRIES
#define HTTPD_MAX_RETRIES 4
#endif
/** The poll delay is X*500ms */
#ifndef HTTPD_POLL_INTERVAL
#define HTTPD_POLL_INTERVAL 4
#endif
/** Priority for tcp pcbs created by HTTPD (very low by default).
* Lower priorities get killed first when running out of memroy.
*/
#ifndef HTTPD_TCP_PRIO
#define HTTPD_TCP_PRIO TCP_PRIO_MIN
#endif
/** Set this to 1 to enabled timing each file sent */
#ifndef LWIP_HTTPD_TIMING
#define LWIP_HTTPD_TIMING 0
#endif
#ifndef HTTPD_DEBUG_TIMING
#define HTTPD_DEBUG_TIMING LWIP_DBG_OFF
#endif
/** Set this to 1 on platforms where strnstr is not available */
#ifndef LWIP_HTTPD_STRNSTR_PRIVATE
#define LWIP_HTTPD_STRNSTR_PRIVATE 1
#endif
/** Set this to one to show error pages when parsing a request fails instead
of simply closing the connection. */
#ifndef LWIP_HTTPD_SUPPORT_EXTSTATUS
#define LWIP_HTTPD_SUPPORT_EXTSTATUS 0
#endif
/** Set this to 0 to drop support for HTTP/0.9 clients (to save some bytes) */
#ifndef LWIP_HTTPD_SUPPORT_V09
#define LWIP_HTTPD_SUPPORT_V09 1
#endif
/** Set this to 1 to support HTTP request coming in in multiple packets/pbufs */
#ifndef LWIP_HTTPD_SUPPORT_REQUESTLIST
#define LWIP_HTTPD_SUPPORT_REQUESTLIST 1
#endif
#if LWIP_HTTPD_SUPPORT_REQUESTLIST
/** Number of rx pbufs to enqueue to parse an incoming request (up to the first
newline) */
#ifndef LWIP_HTTPD_REQ_QUEUELEN
#define LWIP_HTTPD_REQ_QUEUELEN 10
#endif
/** Number of (TCP payload-) bytes (in pbufs) to enqueue to parse and incoming
request (up to the first double-newline) */
#ifndef LWIP_HTTPD_REQ_BUFSIZE
#define LWIP_HTTPD_REQ_BUFSIZE LWIP_HTTPD_MAX_REQ_LENGTH
#endif
/** Defines the maximum length of a HTTP request line (up to the first CRLF,
copied from pbuf into this a global buffer when pbuf- or packet-queues
are received - otherwise the input pbuf is used directly) */
#ifndef LWIP_HTTPD_MAX_REQ_LENGTH
#define LWIP_HTTPD_MAX_REQ_LENGTH 1023
#endif
#endif /* LWIP_HTTPD_SUPPORT_REQUESTLIST */
/** Maximum length of the filename to send as response to a POST request,
* filled in by the application when a POST is finished.
*/
#ifndef LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN
#define LWIP_HTTPD_POST_MAX_RESPONSE_URI_LEN 63
#endif
/** Set this to 0 to not send the SSI tag (default is on, so the tag will
* be sent in the HTML page */
#ifndef LWIP_HTTPD_SSI_INCLUDE_TAG
#define LWIP_HTTPD_SSI_INCLUDE_TAG 1
#endif
#ifndef true
#define true ((u8_t)1)
#endif
#ifndef false
#define false ((u8_t)0)
#endif
/** Minimum length for a valid HTTP/0.9 request: "GET /\r\n" -> 7 bytes */
#define MIN_REQ_LEN 7
#define CRLF "\r\n"
/** These defines check whether tcp_write has to copy data or not */
#ifndef HTTP_IS_DATA_VOLATILE
#if LWIP_HTTPD_SSI
/* Copy for SSI files, no copy for non-SSI files */
#define HTTP_IS_DATA_VOLATILE(hs) ((hs)->tag_check ? TCP_WRITE_FLAG_COPY : 0)
#else /* LWIP_HTTPD_SSI */
/** Default: don't copy if the data is sent from file-system directly */
#define HTTP_IS_DATA_VOLATILE(hs) (((hs->file != NULL) && (hs->handle != NULL) && (hs->file == \
(char*)hs->handle->data + hs->handle->len - hs->left)) \
? 0 : TCP_WRITE_FLAG_COPY)
#endif /* LWIP_HTTPD_SSI */
#e
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
webserver-master.rar (12个子文件)
webserver-master
webserver.sln 923B
fsdata.h 2KB
fsdata_custom.h 176KB
httpd_cgi_ssi.c 6KB
httpd.h 10KB
httpd.c 70KB
fs.h 4KB
webserver
webserver.ino 1KB
fs.c 5KB
sketch.h 248B
httpd_structs.h 4KB
webserver.vcxproj 29KB
共 12 条
- 1
资源评论
Kinonoyomeo
- 粉丝: 77
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功