lwip-1.4.1 (partial)
Embed:
(wiki syntax)
Show/hide line numbers
http_req.h
00001 /* 00002 * The MIT License (MIT) 00003 * 00004 * Copyright (c) 2015 by Sergey Fetisov <fsenok@gmail.com> 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy 00007 * of this software and associated documentation files (the "Software"), to deal 00008 * in the Software without restriction, including without limitation the rights 00009 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 * copies of the Software, and to permit persons to whom the Software is 00011 * furnished to do so, subject to the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included in all 00014 * copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00022 * SOFTWARE. 00023 */ 00024 00025 /* 00026 * version: 1.0 demo (7.02.2015) 00027 * brief: part of tiny http ipv4 server using lwip (pcb) 00028 */ 00029 00030 #ifndef HTTP_REQ_H 00031 #define HTTP_REQ_H 00032 00033 #include <stdio.h> 00034 #include <stdbool.h> 00035 #include <stdint.h> 00036 #include <string.h> 00037 #include <stdlib.h> 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 #include "cparser.h" 00044 00045 //#define HTTP_REQ_MAX_SIZE 512 00046 #define HTTP_REQ_MAX_PARAMS 32 00047 00048 typedef enum http_method 00049 { 00050 METHOD_NONE, 00051 METHOD_GET, 00052 METHOD_POST, 00053 METHOD_HEAD, 00054 METHOD_PUT, 00055 METHOD_CONNECT, 00056 METHOD_OPTIONS, 00057 METHOD_DELETE, 00058 METHOD_TRACE, 00059 METHOD_PATCH 00060 } http_mt_t; 00061 00062 typedef enum http_conn_type 00063 { 00064 CT_NONE, 00065 CT_CLOSE, 00066 CT_KEEP_ALIVE 00067 } http_ct_t; 00068 00069 extern const char MIME_TEXT_HTML[]; // text/html 00070 extern const char MIME_TEXT_HTML[]; // text/javascript 00071 extern const char MIME_TEXT_PLAIN[]; // text/plain 00072 extern const char MIME_TEXT_XML[]; // text/xml 00073 extern const char MIME_TEXT_CSS[]; // text/css 00074 extern const char MIME_IMAGE_GIF[]; // image/gif 00075 extern const char MIME_IMAGE_JPEG[]; // image/jpeg 00076 extern const char MIME_IMAGE_PJPEG[]; // image/pjpeg 00077 extern const char MIME_IMAGE_PNG[]; // image/png 00078 extern const char MIME_IMAGE_SVG[]; // image/svg+xml 00079 extern const char MIME_IMAGE_TIFF[]; // image/tiff 00080 extern const char MIME_IMAGE_ICON[]; // image/vnd.microsoft.icon 00081 extern const char MIME_IMAGE_WBMP[]; // image/vnd.wap.wbmp 00082 00083 typedef struct http_req 00084 { 00085 http_mt_t method; // GET 00086 char *uri; // /path/resource 00087 int num_params; // 2 00088 char *params[HTTP_REQ_MAX_PARAMS]; // param1, param2 00089 char *values[HTTP_REQ_MAX_PARAMS]; // value1, value2 00090 char *ver; // HTTP/1.1 00091 char *host; // Host: [wikipedia.org] 00092 char *user_agent; // User-Agent: [Mozilla/5.0] 00093 char *mime; // Content-Type: [multipart/form-data; boundary="Asrf456BGe4h"] 00094 int cont_len; // Content-Length: [123] 00095 char *accept; // Accept: [text/html] 00096 char *accept_lang; // Accept-Language: [en-US;q=0.5,en;q=0.3] 00097 char *accept_enc; // Accept-Encoding: [gzip, deflate] 00098 char *cookie; // Cookie: [Cookie data] 00099 http_ct_t conn_type; // Connection: [keep-alive] 00100 int keep_alive; // Keep-Alive: [300] 00101 } http_req_t; 00102 00103 typedef struct http_resp 00104 { 00105 int code; // HTTP/1.1 [200] OK 00106 const char *server; // Server: [lrndis] 00107 const char *cont_lang; // Content-Language: [ru] 00108 const char *mime; // Content-Type: [text/html; charset=utf-8] 00109 int cont_len; // Content-Length: [1234] 00110 http_ct_t conn_type; // Connection: [close] 00111 } http_resp_t; 00112 00113 // HTTP REQUEST BUFFER 00114 00115 typedef enum http_reqb_state 00116 { 00117 REQB_UNFINISHED, 00118 REQB_FINISHED, 00119 REQB_SYNT_ERROR, 00120 REQB_REQ_TO_BIG 00121 } http_reqb_state_t; 00122 00123 typedef struct http_reqb 00124 { 00125 http_req_t req; 00126 http_reqb_state_t state; 00127 //char buff[HTTP_REQ_MAX_SIZE]; 00128 char *buff; 00129 int bsize; 00130 int size; 00131 struct 00132 { 00133 int pos; 00134 int state; 00135 } parsing; 00136 } http_reqb_t; 00137 00138 void http_reqb_init(http_reqb_t *reqb, void *buff, int size); 00139 int http_reqb_avail(const http_reqb_t *reqb); 00140 void http_reqb_push(http_reqb_t *rb, const void *data, int size); 00141 int http_resp_len(const http_resp_t *resp); 00142 int http_resp_str(const http_resp_t *resp, char *str, int size); 00143 00144 #ifdef __cplusplus 00145 } 00146 #endif 00147 00148 #endif
Generated on Wed Jul 13 2022 09:48:37 by 1.7.2