net/http.h File Reference


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 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 Documentation

#define HTTP_END_OF_VAR   (0xFFFF)

Examples:
ex_httpgetvar.c, and ex_httpgetvar2.c.

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

Examples:
ex_httpgetvar.c.


Typedef Documentation

typedef struct _HTTP_INFO HTTP_INFO

typedef struct _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


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_DISCONNECT 
SM_HTTP_DISCONNECT_WAIT 

enum _SM_HTTP_GET

Enumerator:
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

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

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 *.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.

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 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 Mon Oct 9 13:22:07 2006 for SBC65EC Web Server by  doxygen 1.4.7