Httpd server.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include "lwipopts.h"
#include "lwip/ip.h"
#include <string.h>
#include "lwip/tcp.h"
#include "fs.h"
#include "afec.h"
#include "httpd.h"
#include "cgi.h"
Data Structures | |
struct | http_state |
state info for file sending by http More... | |
Macros | |
#define | HTTP_DEFAULT_PAGE "index.html" |
#define | STEP_AT_27C 144 * 4096 / 330 |
Functions | |
const char * | get_ext (const char *name) |
Get filename extension type. More... | |
static err_t | http_accept (void *arg, struct tcp_pcb *pcb, err_t err) |
Accept incoming HTTP connection requests. More... | |
static void | http_close_conn (struct tcp_pcb *pcb, struct http_state *hs) |
Close HTTP connection. More... | |
static void | http_conn_err (void *arg, err_t err) |
Callback called on connection error. More... | |
static void | http_decodeUrl (const char *raw_buf, size_t raw_len, char *decodec_buf, size_t len) |
Decode URL. More... | |
static void | http_getPageName (const char *recv_buf, size_t recv_len, char *page_name, size_t len) |
Get requested page name. More... | |
int | http_getValue (char *tolenized_buf, size_t tolenized_buf_len, const char *key, char *value, size_t len) |
Get key value from tokenized buffer. More... | |
static char | http_hexToAscii (char first, char second) |
ASCII to HEX converter. More... | |
void | http_init (void) |
HTTP server init. More... | |
static err_t | http_poll (void *arg, struct tcp_pcb *pcb) |
Poll for HTTP data. More... | |
static err_t | http_recv (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) |
Core HTTP server receive function. More... | |
static int | http_searchContentType (const char *name) |
Match content type based on filename extension. More... | |
static void | http_send_data (struct tcp_pcb *pcb, struct http_state *hs) |
Send HTTP data. More... | |
void | http_sendInternalErr (int content_type) |
Send HTTP internal server error code. More... | |
void | http_sendOk (int content_type) |
Send the HTTP header with the appropriated content type. More... | |
static err_t | http_sent (void *arg, struct tcp_pcb *pcb, u16_t len) |
Callback to handle data transfered. More... | |
int | http_tokenizeGetRequest (char *raw_buf, size_t raw_len) |
Tokenize a buffer. More... | |
void | http_write (const char *buf, u32_t len) |
Write HTTP data. More... | |
Variables | |
static char | decoded_str [80] |
struct http_state * | g_hs |
struct tcp_pcb * | g_pcb |
struct { | |
const char * content | |
const char * key | |
} | http_content_type [] |
http content type indicated with keys More... | |
static const char | http_html_hdr_200 [] = "HTTP/1.0 200 OK\r\n" |
http html header More... | |
static const char | http_html_hdr_404 [] = "HTTP/1.0 404 Not Found\r\n" |
static const char | http_html_hdr_500 [] = "HTTP/1.0 500 Internal Server Error\r\n" |
const char | http_server_error [] |
http error page html More... | |
static char | req_string [80] |
Handle the incoming client request. More... | |
BoardStatus | status |
board status info More... | |
#define HTTP_DEFAULT_PAGE "index.html" |
Referenced by http_recv().
#define STEP_AT_27C 144 * 4096 / 330 |
Referenced by http_accept().
const char* get_ext | ( | const char * | name | ) |
Get filename extension type.
name | String containing a filename. |
References NULL.
Referenced by cgi_search(), and http_searchContentType().
Accept incoming HTTP connection requests.
arg | Pointer to structure representing the HTTP state. |
pcb | Pointer to a TCP connection structure. |
err | Connection status. |
References afec_channel_get_value(), AFEC_TEMPERATURE_SENSOR, ERR_MEM, ERR_OK, http_state::file, http_conn_err(), http_poll(), http_recv(), BoardStatus::internal_temp, http_state::left, LWIP_UNUSED_ARG, mem_malloc(), NULL, http_state::retries, STEP_AT_27C, tcp_arg(), tcp_err(), tcp_poll(), TCP_PRIO_MIN, tcp_recv(), and tcp_setprio().
Referenced by http_init().
|
static |
Close HTTP connection.
pcb | Pointer to a TCP connection structure. |
hs | Pointer to structure representing the HTTP state. |
References mem_free(), NULL, tcp_arg(), tcp_close(), tcp_recv(), and tcp_sent().
Referenced by http_recv(), and http_sent().
Callback called on connection error.
arg | Pointer to structure representing the HTTP state. |
err | Error code. |
References arg, LWIP_UNUSED_ARG, and mem_free().
Referenced by http_accept().
|
static |
Decode URL.
raw_buf | Input buffer. |
raw_len | Input buffer length. |
decodec_buf | Output decoded buffer. |
len | Output buffer length. |
References http_hexToAscii().
Referenced by http_getValue().
|
static |
Get requested page name.
recv_buf | Receive buffer. |
recv_len | Receive buffer length. |
page_name | Output buffer to store requestd page name. |
len | Output buffer length. |
Referenced by http_recv().
int http_getValue | ( | char * | tolenized_buf, |
size_t | tolenized_buf_len, | ||
const char * | key, | ||
char * | value, | ||
size_t | len | ||
) |
Get key value from tokenized buffer.
tolenized_buf | . |
tolenized_buf_len | . |
key | . |
value | |
len | . |
References decoded_str, and http_decodeUrl().
Referenced by cgi_displayMsg(), and cgi_led().
|
static |
ASCII to HEX converter.
first | First digit. |
second | Second digit. |
Referenced by http_decodeUrl().
HTTP server init.
References http_accept(), IP_ADDR_ANY, tcp_accept(), tcp_bind(), tcp_listen, and tcp_new().
Referenced by init_ethernet().
Poll for HTTP data.
arg | Pointer to structure representing the HTTP state. |
pcb | Pointer to a TCP connection structure. |
References arg, ERR_ABRT, ERR_OK, http_state::file, http_send_data(), NULL, http_state::retries, and tcp_abort().
Referenced by http_accept().
Core HTTP server receive function.
Handle the requests and process them.
arg | Pointer to structure representing the HTTP state. |
pcb | Pointer to a TCP connection structure. |
p | Incoming connection request. |
err | Connection status. |
References arg, cgi_search(), cgi_table, fs_file::data, ERR_OK, http_state::file, fs_open(), http_close_conn(), HTTP_CONTENT_HTML, HTTP_DEFAULT_PAGE, http_getPageName(), http_html_hdr_404, http_searchContentType(), http_sendInternalErr(), http_sendOk(), http_server_error, http_write(), fs_file::len, pbuf::len, NULL, pbuf::payload, pbuf_free(), req_string, tcp_recved(), and pbuf::tot_len.
Referenced by http_accept().
|
static |
Match content type based on filename extension.
name | String containing a filename. |
References get_ext(), HTTP_CONTENT_CNT, HTTP_CONTENT_JPEG, http_content_type, and key.
Referenced by http_recv().
|
static |
Send HTTP data.
pcb | Pointer to a TCP connection structure. |
hs | Pointer to structure representing the HTTP state. |
References ERR_MEM, ERR_OK, http_state::file, http_state::left, tcp_sndbuf, tcp_write(), and TCP_WRITE_FLAG_COPY.
Referenced by http_poll(), http_sent(), and http_write().
void http_sendInternalErr | ( | int | content_type | ) |
Send HTTP internal server error code.
content_type | HTTP content type. |
References content, http_content_type, http_html_hdr_500, and http_write().
Referenced by cgi_displayMsg(), cgi_led(), and http_recv().
void http_sendOk | ( | int | content_type | ) |
Send the HTTP header with the appropriated content type.
content_type | Index in the http_content_type table. |
References content, http_content_type, http_html_hdr_200, and http_write().
Referenced by cgi_chipInfo(), cgi_displayMsg(), cgi_echo(), cgi_led(), cgi_ledStatus(), cgi_resistor(), cgi_status(), cgi_temp(), cgi_uptime(), and http_recv().
Callback to handle data transfered.
arg | Pointer to structure representing the HTTP state. |
pcb | Pointer to a TCP connection structure. |
len | Unused. |
References arg, ERR_OK, http_close_conn(), http_send_data(), http_state::left, LWIP_UNUSED_ARG, and http_state::retries.
Referenced by http_write().
int http_tokenizeGetRequest | ( | char * | raw_buf, |
size_t | raw_len | ||
) |
Tokenize a buffer.
raw_buf | Buffer to parse. |
raw_len | Buffer length. |
Referenced by cgi_displayMsg(), and cgi_led().
Write HTTP data.
buf | Buffer to write. |
len | Buffer length. |
References http_state::file, http_send_data(), http_sent(), http_state::left, and tcp_sent().
Referenced by cgi_chipInfo(), cgi_echo(), cgi_led(), cgi_ledStatus(), cgi_resistor(), cgi_status(), cgi_temp(), cgi_uptime(), http_recv(), http_sendInternalErr(), and http_sendOk().
const char* content |
Referenced by http_sendInternalErr(), and http_sendOk().
|
static |
Referenced by http_getValue().
struct http_state* g_hs |
struct tcp_pcb* g_pcb |
Referenced by cgi_status().
struct { ... } http_content_type[] |
http content type indicated with keys
Referenced by http_searchContentType(), http_sendInternalErr(), and http_sendOk().
|
static |
http html header
Referenced by http_sendOk().
|
static |
Referenced by http_recv().
|
static |
Referenced by http_sendInternalErr().
const char http_server_error[] |
http error page html
Referenced by http_recv().
const char* key |
Referenced by http_searchContentType().
|
static |
Handle the incoming client request.
Referenced by http_recv().
BoardStatus status |
board status info
Referenced by afec_process_callback(), cgi_led(), cgi_ledStatus(), cgi_status(), cgi_temp(), cgi_uptime(), pio_handler_process(), twi_master_init(), twi_master_read(), twi_master_write(), twi_slave_read(), and twi_slave_write().