lwip-1.4.1 (partial)

Dependents:   IGLOO_board

Committer:
ua1arn
Date:
Tue Jul 24 17:36:01 2018 +0000
Revision:
1:119c4f7144c8
lwip 1.4.1 with necessary servers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ua1arn 1:119c4f7144c8 1 /*
ua1arn 1:119c4f7144c8 2 * The MIT License (MIT)
ua1arn 1:119c4f7144c8 3 *
ua1arn 1:119c4f7144c8 4 * Copyright (c) 2015 by Sergey Fetisov <fsenok@gmail.com>
ua1arn 1:119c4f7144c8 5 *
ua1arn 1:119c4f7144c8 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
ua1arn 1:119c4f7144c8 7 * of this software and associated documentation files (the "Software"), to deal
ua1arn 1:119c4f7144c8 8 * in the Software without restriction, including without limitation the rights
ua1arn 1:119c4f7144c8 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ua1arn 1:119c4f7144c8 10 * copies of the Software, and to permit persons to whom the Software is
ua1arn 1:119c4f7144c8 11 * furnished to do so, subject to the following conditions:
ua1arn 1:119c4f7144c8 12 *
ua1arn 1:119c4f7144c8 13 * The above copyright notice and this permission notice shall be included in all
ua1arn 1:119c4f7144c8 14 * copies or substantial portions of the Software.
ua1arn 1:119c4f7144c8 15 *
ua1arn 1:119c4f7144c8 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ua1arn 1:119c4f7144c8 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ua1arn 1:119c4f7144c8 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ua1arn 1:119c4f7144c8 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ua1arn 1:119c4f7144c8 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ua1arn 1:119c4f7144c8 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
ua1arn 1:119c4f7144c8 22 * SOFTWARE.
ua1arn 1:119c4f7144c8 23 */
ua1arn 1:119c4f7144c8 24
ua1arn 1:119c4f7144c8 25 /*
ua1arn 1:119c4f7144c8 26 * version: 1.0 demo (7.02.2015)
ua1arn 1:119c4f7144c8 27 * brief: tiny http ipv4 server using lwip (pcb)
ua1arn 1:119c4f7144c8 28 */
ua1arn 1:119c4f7144c8 29
ua1arn 1:119c4f7144c8 30 #ifndef HTSERV_H
ua1arn 1:119c4f7144c8 31 #define HTSERV_H
ua1arn 1:119c4f7144c8 32
ua1arn 1:119c4f7144c8 33 #include <stdlib.h>
ua1arn 1:119c4f7144c8 34 #include <stdio.h>
ua1arn 1:119c4f7144c8 35 #include "lwip/netif.h"
ua1arn 1:119c4f7144c8 36 #include "lwip/pbuf.h"
ua1arn 1:119c4f7144c8 37 #include "lwip/tcp_impl.h"
ua1arn 1:119c4f7144c8 38 #include "lwip/tcp.h"
ua1arn 1:119c4f7144c8 39 #include "http_req.h"
ua1arn 1:119c4f7144c8 40
ua1arn 1:119c4f7144c8 41 // server configuration
ua1arn 1:119c4f7144c8 42
ua1arn 1:119c4f7144c8 43 #define HTTP_SERVER_NAME "lrndis" // http server name
ua1arn 1:119c4f7144c8 44 #define HTTP_SERVER_MAX_CON 3 // max connections number at one time
ua1arn 1:119c4f7144c8 45 #define HTTP_CON_BUFF_SIZE 2048 // size of con buffer, used for request/response data storing
ua1arn 1:119c4f7144c8 46 #define HTTP_REQ_MAX_SIZE 1024 // max part of con buffer for a request storing
ua1arn 1:119c4f7144c8 47 #define HTTP_DEF_CONT_LANG "en" // content language which will be sent to client by default
ua1arn 1:119c4f7144c8 48
ua1arn 1:119c4f7144c8 49 // http server types
ua1arn 1:119c4f7144c8 50
ua1arn 1:119c4f7144c8 51 typedef enum htserv_err
ua1arn 1:119c4f7144c8 52 {
ua1arn 1:119c4f7144c8 53 HTTP_NO_ERROR,
ua1arn 1:119c4f7144c8 54 HTTP_REQ_SYNT_ERR, // http request synt error
ua1arn 1:119c4f7144c8 55 HTTP_BIG_REQUEST, // http request size more then HTTP_CON_BUFF
ua1arn 1:119c4f7144c8 56 HTTP_RESP_NOMEM, // http response size more then HTTP_CON_BUFF
ua1arn 1:119c4f7144c8 57 HTTP_TRANSP_ERR // http transport error (client disconnected?)
ua1arn 1:119c4f7144c8 58 } htserv_err_t;
ua1arn 1:119c4f7144c8 59
ua1arn 1:119c4f7144c8 60 typedef bool (*htserv_on_req_t)(const http_req_t *req, http_resp_t *resp, void **arg);
ua1arn 1:119c4f7144c8 61 typedef void (*htserv_on_con_t)(int index);
ua1arn 1:119c4f7144c8 62 typedef void (*htserv_on_err_t)(htserv_err_t err);
ua1arn 1:119c4f7144c8 63
ua1arn 1:119c4f7144c8 64 typedef enum htcon_state
ua1arn 1:119c4f7144c8 65 {
ua1arn 1:119c4f7144c8 66 CON_ACTIVE,
ua1arn 1:119c4f7144c8 67 CON_CLOSING,
ua1arn 1:119c4f7144c8 68 CON_CLOSED
ua1arn 1:119c4f7144c8 69 } htcon_state_t;
ua1arn 1:119c4f7144c8 70
ua1arn 1:119c4f7144c8 71 typedef struct htcon
ua1arn 1:119c4f7144c8 72 {
ua1arn 1:119c4f7144c8 73 void *arg;
ua1arn 1:119c4f7144c8 74 http_req_t *req;
ua1arn 1:119c4f7144c8 75 http_resp_t *resp;
ua1arn 1:119c4f7144c8 76 htcon_state_t state;
ua1arn 1:119c4f7144c8 77 int writed;
ua1arn 1:119c4f7144c8 78 } htcon_t;
ua1arn 1:119c4f7144c8 79
ua1arn 1:119c4f7144c8 80 extern htserv_on_req_t htserv_on_req;
ua1arn 1:119c4f7144c8 81 extern htserv_on_con_t htserv_on_con;
ua1arn 1:119c4f7144c8 82 extern htserv_on_err_t htserv_on_err;
ua1arn 1:119c4f7144c8 83
ua1arn 1:119c4f7144c8 84 err_t htserv_init(uint16_t port);
ua1arn 1:119c4f7144c8 85 void htserv_free(void);
ua1arn 1:119c4f7144c8 86 void htserv_tmr(uint32_t time_ms);
ua1arn 1:119c4f7144c8 87 const htcon_t *htcon(int index);
ua1arn 1:119c4f7144c8 88 void htcon_close(int con);
ua1arn 1:119c4f7144c8 89 void htcon_free(int con);
ua1arn 1:119c4f7144c8 90 int htcon_write_avail(int con);
ua1arn 1:119c4f7144c8 91 int htcon_write(int con, const char *data, int size);
ua1arn 1:119c4f7144c8 92
ua1arn 1:119c4f7144c8 93 #endif