net/http.h File Reference

HTTP Module for Modtronix TCP/IP Stack. More...

#include "net\ip.h"
#include "net\tcp.h"
#include "net\fsee.h"
#include "net\security.h"

Data Structures

struct  _HTTP_INFO

Defines

#define HTTP_END_OF_VAR   (0xFFFFul)
#define HTTP_MAX_RESOURCE_NAME_LEN   (12)
#define HTTP_START_OF_VAR   (0x0000ul)

Typedefs

typedef struct _HTTP_INFO HTTP_INFO
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_AUTHENTICATION, 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 HTTPGetCurrentUser (HTTP_INFO *httpInfo)
BYTE HTTPGetParam (TCP_SOCKET s, BYTE *param, BYTE *paramLen)
WORD HTTPGetVar (HTTP_INFO *httpInfo, BYTE *val)
void HTTPInit (void)
void HTTPProcessHdr (HTTP_INFO *httpInfo, BYTE *hdr, BYTE *rqstRes)
void HTTPServer (void)


Detailed Description

HTTP Module for Modtronix TCP/IP Stack.

Author:
Modtronix Engineering
Dependencies:
none
Compiler:
MPLAB C18 v2.10 or higher
HITECH PICC-18 V8.35PL3 or higher

Description

Contains the HTTP Server code.
For a detailed description, see the HTTP Server section of this document - in [Modules] [HTTP Server].

Configuration

The following defines are used to configure this module, and should be placed in the projdefs.h (or similar) file. For details, see Project Configuration. To configure the module, the required defines should be uncommended, and the rest commented out.
 //*********************************************************************
 //--------------------   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 Documentation

#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)

Examples:
ex_httpgetvar.c.


Typedef Documentation

typedef struct _HTTP_INFO HTTP_INFO

typedef enum _SM_HTTP SM_HTTP

typedef enum _SM_HTTP_GET SM_HTTP_GET


Enumeration Type Documentation

enum _SM_HTTP

Enumerator:
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_AUTHENTICATION 
SM_HTTP_DISCONNECT 
SM_HTTP_DISCONNECT_WAIT 

Enumerator:
SM_HTTP_GET_READ 
SM_HTTP_GET_VAR_GRP 
SM_HTTP_GET_VAR_VALMSB 
SM_HTTP_GET_VAR_VALLSB 
SM_HTTP_GET_VAR 

Enumerator:
SM_HTTP_POST_IMAGE 


Function Documentation

void HTTPExecGetCmd ( HTTP_INFO httpInfo,
BYTE rqstRes 
)

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.

Parameters:
httpInfo HTTP_INFO structure of current HTTP connection
rqstRes Name of the Requested resource - GET command's action. All characters are in uppercase!
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.

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!
Examples:
ex_httpexecgetcmd.c.

BYTE HTTPGetCurrentUser ( HTTP_INFO httpInfo  ) 

Returns the current user logged in.

Returns:
The current user logged in. Is a USER_XX constant

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:

  • Pointer to Name parameter = &param[0]
  • Pointer to Value parameter = &param[paramLen]
    Pre-Condition:
    HTTPGetRqstRes() must have already be called.
    Parameters:
    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.
    Returns:
    1 if there are parameters to follow, else 0
Examples:
ex_httpexecgetcmd.c.

WORD HTTPGetVar ( HTTP_INFO httpInfo,
BYTE val 
)

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.

Pre-Condition:
HTTPInit() must already be called.
Parameters:
httpInfo HTTP_INFO structure of HTTP connection requesting this Variable.
val Buffer for value storage.
Returns:
Variable reference as required by application.
Examples:
ex_httpgetvar.c, and ex_httpgetvar2.c.

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

Pre-Condition:
TCP must already be initialized.

void HTTPProcessHdr ( HTTP_INFO httpInfo,
BYTE hdr,
BYTE rqstRes 
)

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.

Parameters:
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.

Pre-Condition:
HTTPInit() must already be called.


Generated on Wed Feb 3 12:45:35 2010 for SBC65EC Web Server by  doxygen 1.5.8