ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
web.h
Go to the documentation of this file.
1 
24 #ifndef __WEB_H__
25 #define __WEB_H__
26 
27 typedef struct espconn espconn_t;
28 
29 // WEB CONNECTIONS
30 #ifndef MAX_CONNECTIONS
31  #define MAX_CONNECTIONS 1
32 #endif
33 
34 // =======================================================
35 // HTML HEADER information
36 typedef struct {
37 // GET /LEDCTL.CGI?led2=on&led3=on HTTP/1.1
38 // TOKEN_GET,TOKEN_POST,TOKEN_HEAD
39  int type;
40  char *filename;
41  char *arg_ptr;
42  char *args;
45  char *connection;
46 // POST msg_pointers
47 // Content-Type: application/x-www-form-urlencoded
48 // Content-Length: 165
49  char *content_type;
51 // Follows msg headers
52  char *msg;
53 } hinfo_t;
54 
55 // =======================================================
56 // Memory buffering for socket reads
57 typedef struct {
58  char *ptr; // Current line
59  char *next; // Next line
60  int size; // memory size
61 } mem_t;
62 
63 // =======================================================
64 // Memory buffering for socket writes
65 #define IO_MAX 512 // buffered IO
66 
67 // HTTP headers from the client
68 enum {
85 };
86 
87 
88 typedef struct {
89  char *pattern;
90  int type;
91 } header_t;
92 
93 //HTTP code descriptions from
94 // HTTP Status Codes for Beginners
95 // All valid HTTP 1.1 Status Codes simply explained.
96 // This article is part of the For Beginners series.
97 // http://www.addedbytes.com/for-beginners/"},
98 // Web Server Status Codes
99 enum {
115 };
116 
117 enum {
131 };
132 
133 typedef struct {
135  char *mime;
136  char *ext1;
137  char *ext2;
138 } mime_t;
139 
140 
141 // =======================================================
142 typedef struct {
144 
145  char *rbuf;
146  int received; // bytes creived
147  int rind; // index into rbuf
148  int rsize; // bytes allocated
149 
150  char *wbuf;
151  int send; // bytes to send
152  int wind; // index into wbuf
153  int wsize; // bytes allocated
154 
155  uint8_t remote_ip[4];
156  uint8_t local_ip[4];
159 
160  int delete; // close connection
161 } rwbuf_t;
162 
163 
164 // ============================================================
165 /* web.c */
166 MEMSPACE void web_sep ( void );
167 MEMSPACE int wait_send ( rwbuf_t *p );
168 MEMSPACE int write_buffer ( rwbuf_t *p );
169 MEMSPACE int write_flush ( rwbuf_t *p );
170 MEMSPACE int write_byte ( rwbuf_t *p , int c );
171 MEMSPACE void led_on ( int led );
172 MEMSPACE void led_off ( int led );
173 MEMSPACE void rwbuf_rinit ( rwbuf_t *p );
174 MEMSPACE void rwbuf_winit ( rwbuf_t *p );
175 MEMSPACE void display_ipv4 ( char *msg , uint8_t *ip , int port );
176 MEMSPACE void rwbuf_delete ( rwbuf_t *p );
177 MEMSPACE rwbuf_t *rwbuf_create ( void );
178 MEMSPACE rwbuf_t *find_connection ( espconn_t *conn , int *index , char *msg );
181 MEMSPACE void write_len ( rwbuf_t *p , char *str , int len );
182 MEMSPACE void write_str ( rwbuf_t *p , char *str );
183 MEMSPACE int vsock_printf ( rwbuf_t *p , const char *fmt , va_list va );
184 MEMSPACE int sock_printf ( rwbuf_t *p , const char *fmt , ...);
185 MEMSPACE int html_msg ( rwbuf_t *p , int status , char type , char *fmt , ...);
186 MEMSPACE char *meminit ( mem_t *p , char *ptr , int size );
187 MEMSPACE char *memgets ( mem_t *p );
188 MEMSPACE char *mime_type ( int type );
189 MEMSPACE int file_type ( char *name );
190 MEMSPACE char *html_status ( int status );
191 MEMSPACE void init_hinfo ( hinfo_t *hi );
192 MEMSPACE int match_headers ( char *str , char **p );
193 MEMSPACE char *process_args ( hinfo_t *hi , char *ptr );
194 MEMSPACE char *first_arg ( hinfo_t *hi );
195 MEMSPACE char *next_arg ( hinfo_t *hi );
196 MEMSPACE char *arg_name ( hinfo_t *hi );
197 MEMSPACE char *arg_value ( hinfo_t *hi );
198 MEMSPACE char *http_value ( hinfo_t *hi , char *str );
199 MEMSPACE int is_header ( char *str , char **p );
200 MEMSPACE char *nextbreak ( char *ptr );
201 MEMSPACE void u5toa ( char *ptr , uint16_t num );
202 MEMSPACE void html_head ( rwbuf_t *p , int status , char type , int len );
203 MEMSPACE int parse_http_request ( rwbuf_t *p , hinfo_t *hi );
204 MEMSPACE int is_cgitoken_char ( int c );
205 MEMSPACE int find_cgitoken_start ( char *str );
206 MEMSPACE int is_cgitoken ( char *str );
207 MEMSPACE int rewrite_cgi_token ( rwbuf_t *p , char *src );
208 MEMSPACE void web_task ( void );
209 MEMSPACE void web_init_connections ( void );
210 MEMSPACE void web_init ( int port );
211 
212 
213 // ============================================================
214 
215 
216 #endif /* end of __WEB_H__ */
MEMSPACE void web_init(int port)
Setup WEB server and accept connections.
Definition: web.c:2490
MEMSPACE void rwbuf_winit(rwbuf_t *p)
Initialize socket send status and write index.
Definition: web.c:453
uint16_t content_length
Definition: web.h:50
MEMSPACE char * nextbreak(char *ptr)
Find next space or ? character.
Definition: web.c:1476
char * rbuf
Definition: web.h:145
MEMSPACE rwbuf_t * rwbuf_create(void)
Create socket read/write buffer for a connection.
Definition: web.c:526
MEMSPACE int write_buffer(rwbuf_t *p)
Socket write buffer for this connection We wait for previous send to complete - then send any new dat...
Definition: web.c:266
int rsize
Definition: web.h:148
MEMSPACE int find_cgitoken_start(char *str)
Find start of CGI token in a string CGI tokens have the following syntax @ They start with "@_" and e...
Definition: web.c:2024
MEMSPACE char * memgets(mem_t *p)
Memory gets function We ASSUME we can replace any with a \0.
Definition: web.c:952
int wsize
Definition: web.h:153
Definition: web.h:122
MEMSPACE int delete_connection(rwbuf_t *p)
Delete our main connection structure and connection buffers.
Definition: web.c:715
char * ptr
Definition: web.h:58
unsigned short uint16_t
Definition: send.c:18
int type
Definition: web.h:39
int send
Definition: web.h:151
MEMSPACE void write_len(rwbuf_t *p, char *str, int len)
Write data using buffered write_byte function.
Definition: web.c:758
char * ext1
Definition: web.h:136
int local_port
Definition: web.h:158
Definition: web.h:70
uint16_t args_length
Definition: web.h:43
MEMSPACE char * http_value(hinfo_t *hi, char *str)
Lookup and argument name and return its value.
Definition: web.c:1422
MEMSPACE int wait_send(rwbuf_t *p)
Wait for buffer to send for this connection If write_buffer sending flag is set then wait for it to c...
Definition: web.c:195
char * next
Definition: web.h:59
MEMSPACE void web_task(void)
Process ALL incoming HTTP requests.
Definition: web.c:2441
int type
Definition: web.h:90
MEMSPACE char * meminit(mem_t *p, char *ptr, int size)
in memory memory gets function
Definition: web.c:933
MEMSPACE void init_hinfo(hinfo_t *hi)
Definition: web.c:1055
MEMSPACE int write_flush(rwbuf_t *p)
Write all outstanding data and wait for it to send.
Definition: web.c:323
Definition: web.h:73
MEMSPACE void web_sep(void)
printer seperator
Definition: web.c:182
MEMSPACE void led_on(int led)
Definition: web.c:374
Definition: web.h:120
MEMSPACE void led_off(int led)
Turn off virtual LED.
Definition: web.c:384
MEMSPACE char * arg_value(hinfo_t *hi)
Return the argument value for current argument.
Definition: web.c:1346
MEMSPACE int sock_printf(rwbuf_t *p, const char *fmt,...)
sock_printf function
Definition: web.c:830
char * mime
Definition: web.h:135
Definition: web.h:76
MEMSPACE int rewrite_cgi_token(rwbuf_t *p, char *src)
Replace CGI token with CGI result CGI tokens have the following syntax @ They start with "@_" and end...
Definition: web.c:2093
Definition: web.h:130
Definition: web.h:72
Definition: web.h:57
MEMSPACE void web_init_connections(void)
Definition: web.c:2475
MEMSPACE char * process_args(hinfo_t *hi, char *ptr)
Process GET argments or POST message name/value data. HTML encoding is done in place often reducting ...
Definition: web.c:1116
Definition: web.h:142
Definition: web.h:123
Definition: web.h:69
MEMSPACE rwbuf_t * find_connection(espconn_t *conn, int *index, char *msg)
Find a read/write socket buffer for an espconn connection.
Definition: web.c:590
MEMSPACE int write_byte(rwbuf_t *p, int c)
Write a byte (buffered) using the rwbuf_t socket buffers for this connection If the buffers are full ...
Definition: web.c:339
Definition: web.h:133
int rind
Definition: web.h:147
int remote_port
Definition: web.h:157
char * html_encoding
Definition: web.h:44
MEMSPACE void html_head(rwbuf_t *p, int status, char type, int len)
Write HTTP Contenet-Type/Content-Length header.
Definition: web.c:1518
Definition: web.h:88
char * pattern
Definition: web.h:89
Definition: web.h:121
char * ext2
Definition: web.h:137
MEMSPACE char * next_arg(hinfo_t *hi)
Find next POST/GET argument We have to skip a name and a value.
Definition: web.c:1247
MEMSPACE char * first_arg(hinfo_t *hi)
Find first POST/GET argument.
Definition: web.c:1235
MEMSPACE int parse_http_request(rwbuf_t *p, hinfo_t *hi)
Get arguments for a GET or POST request.
Definition: web.c:1535
Definition: web.h:125
struct espconn espconn_t
Definition: web.h:27
MEMSPACE char * html_status(int status)
Convert html status into string using http_status table.
Definition: web.c:1030
espconn_t * conn
Definition: web.h:143
MEMSPACE rwbuf_t * create_connection(espconn_t *conn)
Allocate read/write socket buffers and add it to the working pool.
Definition: web.c:669
MEMSPACE char * mime_type(int type)
return strung pointer for mime type index
Definition: web.c:983
MEMSPACE int file_type(char *name)
Determin mimetype using file name extension.
Definition: web.c:996
MEMSPACE int is_cgitoken_char(int c)
test to see if a character is a valid member of the CGI token character set CGI tokens have the follo...
Definition: web.c:1999
MEMSPACE int is_cgitoken(char *str)
Does the string have a CGI TOKEN at the beginning ? CGI tokens have the following syntax @ They start...
Definition: web.c:2051
char * arg_ptr
Definition: web.h:41
int wind
Definition: web.h:152
char * filename
Definition: web.h:40
#define MEMSPACE
Definition: cpu.h:25
Definition: web.h:36
Definition: web.h:71
MEMSPACE void display_ipv4(char *msg, uint8_t *ip, int port)
Display IPV4 address.
Definition: web.c:470
MEMSPACE int is_header(char *str, char **p)
Does the string look like a header token with a ':' ?
Definition: web.c:1451
MEMSPACE int match_headers(char *str, char **p)
Match GET/POST message headers.
Definition: web.c:1077
Definition: web.h:100
MEMSPACE int vsock_printf(rwbuf_t *p, const char *fmt, va_list va)
vsock_printf function
Definition: web.c:808
uint8_t type
Definition: web.h:134
char * connection
Definition: web.h:45
Definition: web.h:126
char * content_type
Definition: web.h:49
unsigned char uint8_t
Definition: send.c:17
MEMSPACE void u5toa(char *ptr, uint16_t num)
Print a decimal number into a string without an EOS.
Definition: web.c:1497
MEMSPACE void write_str(rwbuf_t *p, char *str)
Write string using buffered write_byte function.
Definition: web.c:774
char * msg
Definition: web.h:52
MEMSPACE void rwbuf_delete(rwbuf_t *p)
Delete socket read/write buffers.
Definition: web.c:487
MEMSPACE void rwbuf_rinit(rwbuf_t *p)
Initialize socket read status and read index.
Definition: web.c:439
Definition: web.h:124
int size
Definition: web.h:60
char * wbuf
Definition: web.h:150
MEMSPACE char * arg_name(hinfo_t *hi)
Return the argument name for current argument.
Definition: web.c:1298
char * args
Definition: web.h:42
MEMSPACE int html_msg(rwbuf_t *p, int status, char type, char *fmt,...)
Send an HTML status message to socket.
Definition: web.c:853
int received
Definition: web.h:146