//********************************************************************* //-------------------- Configuration -------------------- //********************************************************************* //Define the port used for the HTTP server, default is 80 #define HTTP_PORT (80) //Comment this line if you do NOT want HTML files to be parsed (replace %xnn tags) #define HTTP_PARSE_FILETYPE_HTML //Comment this line if you do NOT want JavaScript files to be parsed (replace %xnn tags) #define HTTP_PARSE_FILETYPE_JS
#include "net\ip.h"
#include "net\tcp.h"
#include "net\fsee.h"
#include "net\security.h"
Data Structures | |
| struct | _HTTP_INFO |
| struct | _HTTP_USER |
Defines | |
| #define | HTTP_END_OF_VAR (0xFFFF) |
| #define | HTTP_MAX_RESOURCE_NAME_LEN (12) |
| #define | HTTP_PORT (80) |
| #define | HTTP_START_OF_VAR (0x0000) |
Typedefs | |
| typedef _HTTP_INFO | HTTP_INFO |
| typedef _HTTP_USER | HTTP_USER |
| typedef enum _SM_HTTP | SM_HTTP |
| typedef enum _SM_HTTP_GET | SM_HTTP_GET |
| typedef enum _SM_HTTP_POST | SM_HTTP_POST |
Enumerations | |
| enum | _SM_HTTP { SM_HTTP_IDLE, SM_HTTP_GET_TX_HDR, SM_HTTP_GET_TX_BODY, SM_HTTP_POST_RX_HDR, SM_HTTP_POST_RX_BODY, SM_HTTP_NOT_FOUND, SM_HTTP_DISCONNECT, SM_HTTP_DISCONNECT_WAIT } |
| enum | _SM_HTTP_GET { SM_HTTP_GET_READ, SM_HTTP_GET_VAR_GRP, SM_HTTP_GET_VAR_VALMSB, SM_HTTP_GET_VAR_VALLSB, SM_HTTP_GET_VAR } |
| enum | _SM_HTTP_POST { SM_HTTP_POST_IMAGE } |
Functions | |
| void | HTTPExecGetCmd (HTTP_INFO *httpInfo, BYTE *rqstRes) |
| BYTE | HTTPGetParam (TCP_SOCKET s, BYTE *param, BYTE *paramLen) |
| WORD | HTTPGetVar (HTTP_INFO *httpInfo, BYTE *val) |
| void | HTTPInit (void) |
| void | HTTPServer (void) |
| #define HTTP_END_OF_VAR (0xFFFF) |
| #define HTTP_MAX_RESOURCE_NAME_LEN (12) |
Maximum length of a requested resource via HTTP = 8 + 3.
| #define HTTP_PORT (80) |
| #define HTTP_START_OF_VAR (0x0000) |
| typedef struct _HTTP_INFO HTTP_INFO |
| typedef struct _HTTP_USER HTTP_USER |
| 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 | Socket that is currently receiving this HTTP command | |
| rqstRes | Name of the Requested resource - GET command's action. All characters are in uppercase! |
| 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 *.cgi 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 give 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 send HTTP_END_OF_VAR and set var to NULL. 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
| 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.
1.4.7