#include "net\ip.h"
#include "net\tcp.h"
#include "net\fsee.h"
#include "net\security.h"
//********************************************************************* //-------------------- Configuration -------------------- //********************************************************************* //Define the port used for the HTTP server, default is 80 #define DEFAULT_HTTPSRVR_PORT (80ul) //Configured HTTP Server port #define HTTPSRVR_PORT (80ul) //Define as 1 to parse (replace %xnn tags) HTML files, or 0 not to parse them #define HTTP_PARSE_FILETYPE_HTML 0ul //Define as 1 to parse (replace %xnn tags) JavaScript files, or 0 not to parse them #define HTTP_PARSE_FILETYPE_JS 0ul //Define as 1 if Authentication required for all files that start with 'X' character #define HTTP_AUTH_REQ_FOR_X_FILES 1ul //Define as 1 if Authentication required for all #define HTTP_AUTH_REQ_FOR_ALL_FILES 0ul //Define as 1 if Authentication required for all pages with GET Methods #define HTTP_AUTH_REQ_FOR_GET 0ul //Define as 1 if Authentication required for all Dynamic files #define HTTP_AUTH_REQ_FOR_DYN 0ul //Define as 1 if Authentication required for all CGI files #define HTTP_AUTH_REQ_FOR_CGI 0ul //Define as 1 if Authentication required for all Secure Tags #define HTTP_AUTH_REQ_FOR_SECTAG 1ul //Included this define if the user application will process HTTP headers. It it does, //the HTTPProcessHdr() callback function must be implemented by the user #define HTTP_USER_PROCESSES_HEADERS
#define HTTP_END_OF_VAR (0xFFFFul) |
#define HTTP_MAX_RESOURCE_NAME_LEN (12) |
Maximum length of a requested resource via HTTP = 8 + 3.
#define HTTP_START_OF_VAR (0x0000ul) |
typedef struct _HTTP_INFO HTTP_INFO |
typedef enum _SM_HTTP_GET SM_HTTP_GET |
typedef enum _SM_HTTP_POST SM_HTTP_POST |
enum _SM_HTTP |
enum _SM_HTTP_GET |
enum _SM_HTTP_POST |
This function is a "callback" from HTTPServer task. Whenever a remote node performs interactive GET task on page that was served, HTTPServer calls this functions. Use HTTPGetParam() to get all name-value parameters.
httpInfo | HTTP_INFO structure of current HTTP connection | |
rqstRes | Name of the Requested resource - GET command's action. All characters are in uppercase! |
httpInfo | Socket that is currently receiving this HTTP command | |
rqstRes | Name of the Requested resource - GET command's action. All characters are in uppercase! |
Returns the current user logged in.
BYTE HTTPGetParam | ( | TCP_SOCKET | s, | |
BYTE * | param, | |||
BYTE * | paramLen | |||
) |
Writes the name and value string to given param buffer. Both strings are NULL terminated. On return name ane value string can be accessed as follows:
s | TCP Socket from which to read the next name-value parameter (if any) | |
param | Will hold name and value strings when returning | |
paramLen | On entry into routine holds lengh of param buffer. Will hold Index of value string on return, or 0 if there were none. |
This is a callback function from the HTTPServer() to the main application. This function must be implemented by the user somewhere in the code. Whenever a variable substitution is required (the parsed web pages contains a "\%nxx" tag) on any Dynamic pages, HTTPServer calls this function. This function is responsible for replacing this variable ("\%nxx" tag") with a user defined string. For example, the user might want to replace any "\%a00" tag found on a web page with the value of channel 0 of the analog input. When the "\%a00" is found on a web page, the HTTPServer will call this function, and the user can then return a string representing the value of channel 0 of the analog input.
The given HTTP_INFO structure contains a 8-bit variable reference (httpInfo->VarRef), a 8-bit variable group (httpInfo->var.get.tagGroup) and a 16-bit variable value (httpInfo->var.get.tagVal).
The variable reference indicates whether this is a first call or not.
The variable group and variable value gives the group and value of the tag found on the web page.
Applications should return one character at a time as a variable value. If there are no more characters, or the requeseted variable is not found, this function must set val to NULL. Since this function only allows one character to be returned at a time as part of the variable value, HTTPServer() calls this function multiple times until the user application indicates that there are no more values left for this variable. On begining, HTTPGetVar() is called with the variable reference (httpInfo->var.get.varRef) = HTTP_START_OF_VAR to indicate that this is a first call. Applications should use this reference to start the variable value extraction and return updated reference. If there are no more values left for this variable the application should return HTTP_END_OF_VAR. If there are any bytes left to be sent, the application should return a value other than HTTP_START_OF_VAR or HTTP_END_OF_VAR.
httpInfo | HTTP_INFO structure of HTTP connection requesting this Variable. | |
val | Buffer for value storage. |
void HTTPInit | ( | void | ) |
Set all HTTP connections to Listening state. Initialize FSM for each connection. This function is called only one during lifetime of the application. Modifies HTTP FSM and connections are initialized
This function is a "callback" from HTTPServer task. For each HTTP Header found in the HTTP Request message from the client, this function is called. The application has the chance to parse the received headers.
httpInfo | HTTP_INFO structure of current HTTP connection | |
hdr | Buffer containing NULL terminated header to handle | |
rqstRes | Name of the Requested resource - GET command's action. All characters are in uppercase! |
void HTTPServer | ( | void | ) |
Itterate through all connections and let it handle its connection. If a connection is not finished, do not process next connections. This must be done, all connections use some static variables that are common. This function acts as a task (similar to one in RTOS). This function performs its task in co-operative manner. Main application must call this function repeatdly to ensure all open or new connections are served on time.