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: part of tiny http ipv4 server using lwip (pcb)
ua1arn 1:119c4f7144c8 28 */
ua1arn 1:119c4f7144c8 29
ua1arn 1:119c4f7144c8 30 #ifndef HTTP_REQ_H
ua1arn 1:119c4f7144c8 31 #define HTTP_REQ_H
ua1arn 1:119c4f7144c8 32
ua1arn 1:119c4f7144c8 33 #include <stdio.h>
ua1arn 1:119c4f7144c8 34 #include <stdbool.h>
ua1arn 1:119c4f7144c8 35 #include <stdint.h>
ua1arn 1:119c4f7144c8 36 #include <string.h>
ua1arn 1:119c4f7144c8 37 #include <stdlib.h>
ua1arn 1:119c4f7144c8 38
ua1arn 1:119c4f7144c8 39 #ifdef __cplusplus
ua1arn 1:119c4f7144c8 40 extern "C" {
ua1arn 1:119c4f7144c8 41 #endif
ua1arn 1:119c4f7144c8 42
ua1arn 1:119c4f7144c8 43 #include "cparser.h"
ua1arn 1:119c4f7144c8 44
ua1arn 1:119c4f7144c8 45 //#define HTTP_REQ_MAX_SIZE 512
ua1arn 1:119c4f7144c8 46 #define HTTP_REQ_MAX_PARAMS 32
ua1arn 1:119c4f7144c8 47
ua1arn 1:119c4f7144c8 48 typedef enum http_method
ua1arn 1:119c4f7144c8 49 {
ua1arn 1:119c4f7144c8 50 METHOD_NONE,
ua1arn 1:119c4f7144c8 51 METHOD_GET,
ua1arn 1:119c4f7144c8 52 METHOD_POST,
ua1arn 1:119c4f7144c8 53 METHOD_HEAD,
ua1arn 1:119c4f7144c8 54 METHOD_PUT,
ua1arn 1:119c4f7144c8 55 METHOD_CONNECT,
ua1arn 1:119c4f7144c8 56 METHOD_OPTIONS,
ua1arn 1:119c4f7144c8 57 METHOD_DELETE,
ua1arn 1:119c4f7144c8 58 METHOD_TRACE,
ua1arn 1:119c4f7144c8 59 METHOD_PATCH
ua1arn 1:119c4f7144c8 60 } http_mt_t;
ua1arn 1:119c4f7144c8 61
ua1arn 1:119c4f7144c8 62 typedef enum http_conn_type
ua1arn 1:119c4f7144c8 63 {
ua1arn 1:119c4f7144c8 64 CT_NONE,
ua1arn 1:119c4f7144c8 65 CT_CLOSE,
ua1arn 1:119c4f7144c8 66 CT_KEEP_ALIVE
ua1arn 1:119c4f7144c8 67 } http_ct_t;
ua1arn 1:119c4f7144c8 68
ua1arn 1:119c4f7144c8 69 extern const char MIME_TEXT_HTML[]; // text/html
ua1arn 1:119c4f7144c8 70 extern const char MIME_TEXT_HTML[]; // text/javascript
ua1arn 1:119c4f7144c8 71 extern const char MIME_TEXT_PLAIN[]; // text/plain
ua1arn 1:119c4f7144c8 72 extern const char MIME_TEXT_XML[]; // text/xml
ua1arn 1:119c4f7144c8 73 extern const char MIME_TEXT_CSS[]; // text/css
ua1arn 1:119c4f7144c8 74 extern const char MIME_IMAGE_GIF[]; // image/gif
ua1arn 1:119c4f7144c8 75 extern const char MIME_IMAGE_JPEG[]; // image/jpeg
ua1arn 1:119c4f7144c8 76 extern const char MIME_IMAGE_PJPEG[]; // image/pjpeg
ua1arn 1:119c4f7144c8 77 extern const char MIME_IMAGE_PNG[]; // image/png
ua1arn 1:119c4f7144c8 78 extern const char MIME_IMAGE_SVG[]; // image/svg+xml
ua1arn 1:119c4f7144c8 79 extern const char MIME_IMAGE_TIFF[]; // image/tiff
ua1arn 1:119c4f7144c8 80 extern const char MIME_IMAGE_ICON[]; // image/vnd.microsoft.icon
ua1arn 1:119c4f7144c8 81 extern const char MIME_IMAGE_WBMP[]; // image/vnd.wap.wbmp
ua1arn 1:119c4f7144c8 82
ua1arn 1:119c4f7144c8 83 typedef struct http_req
ua1arn 1:119c4f7144c8 84 {
ua1arn 1:119c4f7144c8 85 http_mt_t method; // GET
ua1arn 1:119c4f7144c8 86 char *uri; // /path/resource
ua1arn 1:119c4f7144c8 87 int num_params; // 2
ua1arn 1:119c4f7144c8 88 char *params[HTTP_REQ_MAX_PARAMS]; // param1, param2
ua1arn 1:119c4f7144c8 89 char *values[HTTP_REQ_MAX_PARAMS]; // value1, value2
ua1arn 1:119c4f7144c8 90 char *ver; // HTTP/1.1
ua1arn 1:119c4f7144c8 91 char *host; // Host: [wikipedia.org]
ua1arn 1:119c4f7144c8 92 char *user_agent; // User-Agent: [Mozilla/5.0]
ua1arn 1:119c4f7144c8 93 char *mime; // Content-Type: [multipart/form-data; boundary="Asrf456BGe4h"]
ua1arn 1:119c4f7144c8 94 int cont_len; // Content-Length: [123]
ua1arn 1:119c4f7144c8 95 char *accept; // Accept: [text/html]
ua1arn 1:119c4f7144c8 96 char *accept_lang; // Accept-Language: [en-US;q=0.5,en;q=0.3]
ua1arn 1:119c4f7144c8 97 char *accept_enc; // Accept-Encoding: [gzip, deflate]
ua1arn 1:119c4f7144c8 98 char *cookie; // Cookie: [Cookie data]
ua1arn 1:119c4f7144c8 99 http_ct_t conn_type; // Connection: [keep-alive]
ua1arn 1:119c4f7144c8 100 int keep_alive; // Keep-Alive: [300]
ua1arn 1:119c4f7144c8 101 } http_req_t;
ua1arn 1:119c4f7144c8 102
ua1arn 1:119c4f7144c8 103 typedef struct http_resp
ua1arn 1:119c4f7144c8 104 {
ua1arn 1:119c4f7144c8 105 int code; // HTTP/1.1 [200] OK
ua1arn 1:119c4f7144c8 106 const char *server; // Server: [lrndis]
ua1arn 1:119c4f7144c8 107 const char *cont_lang; // Content-Language: [ru]
ua1arn 1:119c4f7144c8 108 const char *mime; // Content-Type: [text/html; charset=utf-8]
ua1arn 1:119c4f7144c8 109 int cont_len; // Content-Length: [1234]
ua1arn 1:119c4f7144c8 110 http_ct_t conn_type; // Connection: [close]
ua1arn 1:119c4f7144c8 111 } http_resp_t;
ua1arn 1:119c4f7144c8 112
ua1arn 1:119c4f7144c8 113 // HTTP REQUEST BUFFER
ua1arn 1:119c4f7144c8 114
ua1arn 1:119c4f7144c8 115 typedef enum http_reqb_state
ua1arn 1:119c4f7144c8 116 {
ua1arn 1:119c4f7144c8 117 REQB_UNFINISHED,
ua1arn 1:119c4f7144c8 118 REQB_FINISHED,
ua1arn 1:119c4f7144c8 119 REQB_SYNT_ERROR,
ua1arn 1:119c4f7144c8 120 REQB_REQ_TO_BIG
ua1arn 1:119c4f7144c8 121 } http_reqb_state_t;
ua1arn 1:119c4f7144c8 122
ua1arn 1:119c4f7144c8 123 typedef struct http_reqb
ua1arn 1:119c4f7144c8 124 {
ua1arn 1:119c4f7144c8 125 http_req_t req;
ua1arn 1:119c4f7144c8 126 http_reqb_state_t state;
ua1arn 1:119c4f7144c8 127 //char buff[HTTP_REQ_MAX_SIZE];
ua1arn 1:119c4f7144c8 128 char *buff;
ua1arn 1:119c4f7144c8 129 int bsize;
ua1arn 1:119c4f7144c8 130 int size;
ua1arn 1:119c4f7144c8 131 struct
ua1arn 1:119c4f7144c8 132 {
ua1arn 1:119c4f7144c8 133 int pos;
ua1arn 1:119c4f7144c8 134 int state;
ua1arn 1:119c4f7144c8 135 } parsing;
ua1arn 1:119c4f7144c8 136 } http_reqb_t;
ua1arn 1:119c4f7144c8 137
ua1arn 1:119c4f7144c8 138 void http_reqb_init(http_reqb_t *reqb, void *buff, int size);
ua1arn 1:119c4f7144c8 139 int http_reqb_avail(const http_reqb_t *reqb);
ua1arn 1:119c4f7144c8 140 void http_reqb_push(http_reqb_t *rb, const void *data, int size);
ua1arn 1:119c4f7144c8 141 int http_resp_len(const http_resp_t *resp);
ua1arn 1:119c4f7144c8 142 int http_resp_str(const http_resp_t *resp, char *str, int size);
ua1arn 1:119c4f7144c8 143
ua1arn 1:119c4f7144c8 144 #ifdef __cplusplus
ua1arn 1:119c4f7144c8 145 }
ua1arn 1:119c4f7144c8 146 #endif
ua1arn 1:119c4f7144c8 147
ua1arn 1:119c4f7144c8 148 #endif