#include <stdio.h>
#include <string.h>
#include "conf_eth.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "serial.h"
#include "portmacro.h"
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include "lwip/init.h"
#include "ctrl_access.h"
#include "fsaccess.h"
#include "config_file.h"
#include "ethernet.h"
#include "supervisor.h"
#include "shell.h"
#include "datalog.h"
#include "defaultpage.htm.h"
#include "tracedump.h"
#include "BasicWEB.h"
Macros | |
#define | ERR_BUFFER_SIZE 512 |
#define | ERR_DIR "errors" |
#define | HTTP_CONFIG_FILE "A:/CFG/http.txt" |
#define | webCONN_TIMEOUT 5000 |
#define | webHTTP_CONNECTION_PRIORITY (CTRLPANEL_WEB_SERVER_PRIORITY+1) |
#define | webHTTP_CONNECTION_STACK_SIZE 384 |
#define | webHTTP_NB_CONN 1 |
#define | webHTTP_PORT ( 80 ) |
#define | webMAX_DATA_TO_SEND webNB_SECTOR_TO_SEND * FS_SIZE_OF_SECTOR |
#define | webNB_SECTOR_TO_SEND 4 |
#define | webSERVER_FOLDER "A:/WEB/" |
#define | webSERVER_PROTOCOL "HTTP/1.1" |
#define | webSERVER_SOFTWARE "AVR32 UC3 WEB SERVER" |
#define | webSHORT_DELAY ( 10 ) |
Typedefs | |
typedef ssize_t(* | pf_read_src )(int fd, void *buf, size_t count) |
Functions | |
eExecStatus | e_webserver_cmd_get_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The get webserver config command: get the config fields value of http port Takes no parameter. More... | |
eExecStatus | e_webserver_cmd_set_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The set webserver config command: set the http port. Takes one parameter : port=ppppp. More... | |
portTASK_FUNCTION (vBasicWEBServer, pvParameters) | |
WEB server main task check for incoming connection and process it. More... | |
portTASK_FUNCTION (prvweb_ProcessSingleConnection, pvParameters) | |
process an incoming connection parse the request and close/delete the connection More... | |
portTASK_FUNCTION_PROTO (prvweb_ProcessSingleConnection, pvParameters) | |
static unsigned portLONG | prulweb_BuildErrorBody (portCHAR *response, int s, char *title, const char *text) |
build the static error page body More... | |
static unsigned portLONG | prulweb_BuildErrorTail (portCHAR *response) |
build the static error page tail More... | |
static unsigned portLONG | prulweb_BuildHeaders (portCHAR *response, int s, char *title, char *extra_header, char *me, char *mt) |
build the HTTP header More... | |
static ssize_t | prv_read_default_page (int fd, void *buf, size_t count) |
Copy part of the Default html page to another buffer. More... | |
static void | prvweb_ParseCGIRequest (struct netconn *pxNetCon, char *request) |
parse the CGI request and send it to the shell More... | |
static void | prvweb_ParseHTMLRequest (struct netconn *pxNetCon) |
parse the incoming request parse the HTML request and send file or execute CGI request More... | |
static void | prvweb_SendErrorPage (struct netconn *pxNetCon, int s, char *extra_header, const char *text) |
send the static error page More... | |
static void | prvweb_SendFile (struct netconn *pxNetCon, char *filename) |
parse the file request and send the requested file to the host More... | |
Variables | |
static portSHORT | sCurrentNbHTTPConn = 0 |
xTaskHandle | tTaskHandle [webHTTP_NB_CONN] = { NULL } |
static unsigned int | webHttpPort = 0 |
static size_t | x_default_page_len |
xSemaphoreHandle | xCFGMutex |
static xSemaphoreHandle | xMutexNbHTTPConn |
xSemaphoreHandle | xWEBMutex |
#define ERR_BUFFER_SIZE 512 |
The error buffer size for error page
Referenced by prvweb_SendErrorPage().
#define ERR_DIR "errors" |
#define HTTP_CONFIG_FILE "A:/CFG/http.txt" |
The config file location
Referenced by e_webserver_cmd_set_config(), and portTASK_FUNCTION().
#define webCONN_TIMEOUT 5000 |
The max timeout before killing all pending tasks (ms)
#define webHTTP_CONNECTION_PRIORITY (CTRLPANEL_WEB_SERVER_PRIORITY+1) |
The priority of a http connection.
Referenced by portTASK_FUNCTION().
#define webHTTP_CONNECTION_STACK_SIZE 384 |
The stack size of a http connection task
Referenced by portTASK_FUNCTION().
#define webHTTP_NB_CONN 1 |
The max number of simultaneous http connection.
Referenced by portTASK_FUNCTION().
#define webHTTP_PORT ( 80 ) |
The port on which we listen.
Referenced by portTASK_FUNCTION().
#define webMAX_DATA_TO_SEND webNB_SECTOR_TO_SEND * FS_SIZE_OF_SECTOR |
The max amount of fat data to try to send
Referenced by prv_read_default_page(), and prvweb_SendFile().
#define webNB_SECTOR_TO_SEND 4 |
The max number of sector to try to send
Referenced by prvweb_SendFile().
#define webSERVER_FOLDER "A:/WEB/" |
The folder were server files are
Referenced by prvweb_ParseHTMLRequest().
#define webSERVER_PROTOCOL "HTTP/1.1" |
The server protocol.
Referenced by prulweb_BuildHeaders().
#define webSERVER_SOFTWARE "AVR32 UC3 WEB SERVER" |
The server software name.
Referenced by prulweb_BuildErrorTail(), and prulweb_BuildHeaders().
#define webSHORT_DELAY ( 10 ) |
Delay on close error.
Referenced by portTASK_FUNCTION().
eExecStatus e_webserver_cmd_get_config | ( | eModId | xModId, |
signed short | FsNavId, | ||
int | ac, | ||
signed portCHAR * | av[], | ||
signed portCHAR ** | ppcStringReply | ||
) |
The get webserver config command: get the config fields value of http port Takes no parameter.
xModId | Input. The module that is calling this function. |
FsNavId | Ignored. |
ac | Input. The argument counter. For this command, should be 1. |
av | Input. The argument vector. |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
References NULL, pvPortMalloc(), SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, sprintf(), and webHttpPort.
Referenced by e_syscmds_cmd_get_config().
eExecStatus e_webserver_cmd_set_config | ( | eModId | xModId, |
signed short | FsNavId, | ||
int | ac, | ||
signed portCHAR * | av[], | ||
signed portCHAR ** | ppcStringReply | ||
) |
The set webserver config command: set the http port. Takes one parameter : port=ppppp.
xModId | Input. The module that is calling this function. |
FsNavId | Ignored. |
ac | Input. The argument counter. For this command, should be 1. |
av | Input. The argument vector. |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
References config_file_set_value(), HTTP_CONFIG_FILE, NULL, pvPortMalloc(), SHELL_ERRMSG_CONFIGERROR, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, and SHELL_MSG_REBOOT.
Referenced by e_syscmds_cmd_set_config().
portTASK_FUNCTION | ( | vBasicWEBServer | , |
pvParameters | |||
) |
WEB server main task check for incoming connection and process it.
References config_file_get_value(), ERR_OK, HTTP_CONFIG_FILE, netconn_accept(), netconn_bind(), netconn_close(), netconn_delete(), netconn_listen, netconn_new, NETCONN_TCP, NULL, pcDefaultPage, pdFALSE, pdPASS, pdTRUE, prvweb_SendErrorPage(), sCurrentNbHTTPConn, TRACE_COM2, tTaskHandle, vSemaphoreCreateBinary, vTaskDelay(), webHTTP_CONNECTION_PRIORITY, webHTTP_CONNECTION_STACK_SIZE, webHTTP_NB_CONN, webHTTP_PORT, webHttpPort, webSHORT_DELAY, x_default_page_len, x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), xSemaphoreGive, xSemaphoreTake, and xTaskCreate.
portTASK_FUNCTION | ( | prvweb_ProcessSingleConnection | , |
pvParameters | |||
) |
process an incoming connection parse the request and close/delete the connection
References ERR_OK, netconn_close(), netconn_delete(), NULL, pdTRUE, prvweb_ParseHTMLRequest(), sCurrentNbHTTPConn, tTaskHandle, vTaskDelay(), vTaskDelete(), webHTTP_NB_CONN, webSHORT_DELAY, x_supervisor_SemaphoreGive(), xSemaphoreGive, xSemaphoreTake, and xTaskGetCurrentTaskHandle().
portTASK_FUNCTION_PROTO | ( | prvweb_ProcessSingleConnection | , |
pvParameters | |||
) |
|
static |
build the static error page body
response | Input/Output. the buffer to store data. |
s | Input. The error code. |
title | Input. title of the error page. |
text | Input. text to display in the error page. |
References sprintf().
Referenced by prvweb_SendErrorPage().
|
static |
build the static error page tail
response | Input/Output. the buffer to store data. |
References sprintf(), vEthernetGetIPAddr(), and webSERVER_SOFTWARE.
Referenced by prvweb_SendErrorPage().
|
static |
build the HTTP header
response | Input/Output. the buffer to store data. |
s | Input. The page code (200, 404, etc). |
title | Input. title of the page. |
extra_header | Input. text to display in the error page. |
me | Input. MIME encoding, if used. |
mt | Input. MIME type if used. |
References sprintf(), webSERVER_PROTOCOL, and webSERVER_SOFTWARE.
Referenced by prvweb_ParseCGIRequest(), prvweb_SendErrorPage(), and prvweb_SendFile().
Copy part of the Default html page to another buffer.
fd | Input. file descriptor. Ignored. |
buf | Input/ouput. Destination memory ptr. |
count | Input. Amount of bytes to read. |
References FS_SIZE_OF_SECTOR, pcDefaultPage, webMAX_DATA_TO_SEND, and x_default_page_len.
Referenced by prvweb_SendFile().
parse the CGI request and send it to the shell
pxNetCon | Input. The netconn to use to send and receive data. |
request | Input. The incoming CGI request. |
References NAKED_TRACE_COM2, NETCONN_COPY, netconn_write(), NULL, prulweb_BuildHeaders(), pvPortMalloc(), Shell_exec(), SHELL_EXECSTATUS_OK, SYS_MODID_HTTP, and vPortFree().
Referenced by prvweb_ParseHTMLRequest().
parse the incoming request parse the HTML request and send file or execute CGI request
pxNetCon | Input. The netconn to use to send and receive data. |
References ERR_OK, MAX_FILE_PATH_LENGTH, NAKED_TRACE_COM2, netbuf_data(), netbuf_delete(), netconn_recv(), NULL, prvweb_ParseCGIRequest(), prvweb_SendErrorPage(), prvweb_SendFile(), pvPortMalloc(), sprintf(), vPortFree(), and webSERVER_FOLDER.
Referenced by portTASK_FUNCTION().
|
static |
send the static error page
pxNetCon | Input. The netconn to use to send and receive data. |
s | Input. The error code. |
extra_header | Input. data to push in the error answer. |
text | Input. text to display in the error page. |
References ERR_BUFFER_SIZE, NAKED_TRACE_COM2, NETCONN_COPY, netconn_write(), NULL, prulweb_BuildErrorBody(), prulweb_BuildErrorTail(), prulweb_BuildHeaders(), pvPortMalloc(), and vPortFree().
Referenced by portTASK_FUNCTION(), prvweb_ParseHTMLRequest(), and prvweb_SendFile().
parse the file request and send the requested file to the host
pxNetCon | Input. The netconn to use to send and receive data. |
filename | Input. The incoming filename. |
References close, FS_SIZE_OF_SECTOR, fsaccess_file_get_size(), NAKED_TRACE_COM2, NETCONN_COPY, netconn_write(), NULL, O_RDONLY, open(), prulweb_BuildHeaders(), prv_read_default_page(), prvweb_SendErrorPage(), pvPortMalloc(), read, vPortFree(), webMAX_DATA_TO_SEND, webNB_SECTOR_TO_SEND, and x_default_page_len.
Referenced by prvweb_ParseHTMLRequest().
|
static |
Current nb of HTTP connections.
Referenced by portTASK_FUNCTION().
xTaskHandle tTaskHandle[webHTTP_NB_CONN] = { NULL } |
The handlers for connection tasks.
Referenced by portTASK_FUNCTION().
|
static |
HTTP port for server.
Referenced by e_webserver_cmd_get_config(), and portTASK_FUNCTION().
|
static |
The size of the default contant html page.
Referenced by portTASK_FUNCTION(), prv_read_default_page(), and prvweb_SendFile().
xSemaphoreHandle xCFGMutex |
The CFG system mutex.
|
static |
Mutex to access the current_nb_http_conn variable.
xSemaphoreHandle xWEBMutex |
The Web server system mutex.