NetBurner 3.1
HTTP and HTML Functions

Modules

 HTTP Request Types
 

Classes

struct  httpRequestStruct
 
class  pageHandlerCallback
 

Functions

int SendFullResponse (char const *name, int fd)
 Send a file with the proper HTTP header. More...
 
int32_t SendFileFragment (char const *name, int32_t fd, PCSTR url=NULL)
 Send a file fragment without a header. More...
 
void HTTP_Request::ProcessLine (PSTR startofline)
 internal function
 
int HTTP_Request::Respond (int socket)
 internal function
 
bool HTTP_Request::ExtractAuthentication (char **pPassword, char **pUser)
 used to extract user name and password in authentication test
 
 CallBackFunctionPageHandler::CallBackFunctionPageHandler (const char *pUrl, http_gethandlerfunc *pFunction, HTTP_RequestTypes reqType=tGet, int accessGroup=0, bool beforeFiles=false)
 Constructor for HTTP GET callback function. More...
 
HTTP_ACCESS CheckHttpAccess (int sock, int accessGroup, HTTP_Request &Req)
 All HTTP requests go though this function. More...
 
void StartHttp (uint16_t port)
 Start the HTTP web server. Further documentation in the Initialization section Initialization - System Initialization Functions. More...
 
void StopHttp ()
 Stop the HTTP web server. More...
 
void SendHTMLHeader (int sock)
 Send a HTML response header. More...
 
void SendHTMLHeaderWCookie (int sock, char *cookie)
 Send a HTML response header and cookie. More...
 
void SendTextHeader (int sock)
 Send a HTML plain text header. More...
 
void SendGifHeader (int sock)
 Send a HTML GIF header. More...
 
void RedirectResponse (int sock, PCSTR new_page)
 Redirect a HTTP request to a different page. More...
 
void NotFoundResponse (int sock, PCSTR new_page)
 Send a page not found response. More...
 
void ForbiddenResponse (int sock, PCSTR url)
 Send a page is forbidden response. More...
 
void NotAvailableResponse (int sock, PCSTR url)
 Send a response indicating that the requested resource is not available at this time. More...
 
void BadRequestResponse (int sock, PCSTR url, PCSTR data)
 Send a response indicating that the client request itself is faulty in some manner. More...
 
int writeallsafestring (int fd, PCSTR str)
 Send a string and escape all special characters. More...
 
int httpstricmp (PCSTR str1, PCSTR strIsUpper2)
 Special string compare. Returns 1 if the strings match until one string ends with a null (0). More...
 
void RequestAuthentication (int sock, PCSTR name)
 Reject the current HTTP password request, and send a new password request. More...
 
 HtmlPostVariableListCallback::HtmlPostVariableListCallback (const char *pUrl, postvarhandler *pCallback, int accessGroup=0)
 Custom HTTP POST handler function. More...
 
void StartHttps (uint16_t ssl_port, uint16_t http_port)
 Start the HTTPS secure web server. More...
 

Variables

PSTR HTTP_Request::pURL
 Request URL.
 
PSTR HTTP_Request::pAuthorization
 Authorization header if present, otherwise null.
 
PSTR HTTP_Request::pFirstCookie
 First cookie if present, othewise null. More may follow.
 
PSTR HTTP_Request::pData
 Pointer to entire data set. Note: not null terminated.
 
PSTR HTTP_Request::pSep
 Separator for multipart forms, null if not present.
 
PSTR HTTP_Request::last_datarx
 Pointer to last data read, internal use only.
 
PSTR HTTP_Request::wsKey
 Web socket ket, internal use only.
 
PSTR HTTP_Request::wsProtocol
 Web socket prototocl, internal use only.
 
uint16_t HTTP_Request::sep_len
 Length of separator for multipart forms.
 
uint32_t HTTP_Request::content_length
 Content length field from HTML header.
 
uint32_t HTTP_Request::rx_length
 Total bytes receive from request, internal use only.
 
IPADDR HTTP_Request::client_IPaddr
 IP address of client.
 
uint8_t HTTP_Request::websocketFlags
 Web socket flags.
 
HTTP_RequestTypes HTTP_Request::req
 Type of request HTTP Request Types.
 

Detailed Description

Function Documentation

◆ BadRequestResponse()

void BadRequestResponse ( int  sock,
PCSTR  url,
PCSTR  data 
)

Send a response indicating that the client request itself is faulty in some manner.

Parameters
sockSocket to send response
new_pageThe URL of the page to display
dataAn explanation or segment of data to display indicating the fault
Returns
Nothing
See also
RedirectResponse(), NotFoundResponse(), ForbiddenResponse()
NotAvailableResponse()

◆ CallBackFunctionPageHandler()

CallBackFunctionPageHandler::CallBackFunctionPageHandler ( const char *  pUrl,
http_gethandlerfunc *  pFunction,
HTTP_RequestTypes  reqType = tGet,
int  accessGroup = 0,
bool  beforeFiles = false 
)
inline

Constructor for HTTP GET callback function.

Parameters
pUrlPointer to the URL to intercept from normal system processing
pFunctionPointer to the function to call for the requested URL
reqTypeType of request to intercept, HTTP Request Types. Default is tGet
accessGroupPassword group access level
beforeFilestrue = intercept before checking for a file of the same name false = check for any files of the requested name before intercepting
Return values
1,Thecallback function handled the request
2,Thecallback handled the request, but will leave the socket open. This means some other part of your application must close the TCP socket to terminate the request.

◆ CheckHttpAccess()

HTTP_ACCESS CheckHttpAccess ( int  sock,
int  access_level,
HTTP_Request &  Req 
)

All HTTP requests go though this function.

By default the library provides a weak reference implimentaion that approves all transactions. To provide your own just add an implmentaion of this function to your code.

Parameters
sockThe socket the request came in on.
accessGroupThe user defined acess level for this request. See HtmlPageHandler
ReqThe HTTP request wher one can extract the URL , access type password etc if needed
Returns
The desired response.

All HTTP requests go though this function.

Access levels are set either in the html page of the resource itself, in a .nbaccess file in the directory, or in the case of callback functions, as a parameter.

Parameters
sockThe HTTP socket.
access_levelThe access level of the requested resource.
ReqThe HTTP request initiating the callback.

◆ ForbiddenResponse()

void ForbiddenResponse ( int  sock,
PCSTR  url 
)

Send a page is forbidden response.

Parameters
sockSocket to send response
new_pageThe URL of the page to display
Returns
Nothing
See also
RedirectResponse(), NotFoundResponse()
NotAvailableResponse(), BadRequestResponse()

◆ HtmlPostVariableListCallback()

HtmlPostVariableListCallback::HtmlPostVariableListCallback ( const char *  pUrl,
postvarhandler *  pCallback,
int  accessGroup = 0 
)
inline

Custom HTTP POST handler function.

Parameters
pUrlPointer to URL character string
pCallbackPointer to callback function that will process the POST
accessGroupPassword group access
Return values
1if no errors occurred
0otherwise

◆ httpstricmp()

int httpstricmp ( PCSTR  str1,
PCSTR  strIsUpper2 
)

Special string compare. Returns 1 if the strings match until one string ends with a null (0).

strIsUpper2 must be specified in upper case

Used to match URL with stored file prefixes.

Parameters
str1The string to search
strIsUpper2The string to search for, must be specified in upper case
Return values
0if the prefixes do not match
1if the prefixes match

Example: httpstricmp( str1, "LED.HTML");

str1 Return Value
LED 1
led.HTML 1
led.html 1
LED.HTM? 0

◆ NotAvailableResponse()

void NotAvailableResponse ( int  sock,
PCSTR  url 
)

Send a response indicating that the requested resource is not available at this time.

Parameters
sockSocket to send response
new_pageThe URL of the page to display
Returns
Nothing
See also
RedirectResponse(), NotFoundResponse(), ForbiddenResponse()
BadRequestResponse()

◆ NotFoundResponse()

void NotFoundResponse ( int  sock,
PCSTR  new_page 
)

Send a page not found response.

Parameters
sockSocket to send response
new_pageThe URL of the page to display
Returns
Nothing
See also
ForbiddenResponse(), RedirectResponse()
NotAvailableResponse(), BadRequestResponse()

◆ RedirectResponse()

void RedirectResponse ( int  sock,
PCSTR  new_page 
)

Redirect a HTTP request to a different page.

Parameters
sockSocket to send response
new_pageThe URL of the new page
Returns
Nothing
See also
ForbiddenResponse(), ForbiddenResponse(), SendHTMLHeaderWCookie()
NotAvailableResponse(), BadRequestResponse()

◆ RequestAuthentication()

void RequestAuthentication ( int  sock,
PCSTR  name 
)

Reject the current HTTP password request, and send a new password request.

Sends a 401 authentication request to the client.

Parameters
sockThe socket used to send the request
nameThe name that will appear in the password request
Returns
Nothing
See also
CheckAuthentication()

◆ SendFileFragment()

int32_t SendFileFragment ( char const *  name,
int32_t  fd,
PCSTR  url = NULL 
)

Send a file fragment without a header.

This function searches through the files stored in the system by comphtml If it finds the file, it sends the file as a fragment - it does not send a file header. Can be used to build HTML responses with large amounts of data. If the stored file has embedded dynamic HTML the functions will be filled in.

Parameters
nameName of the file
fdFile descriptor used to send the file fragment
urlOptional URL
Return values
1if the file was found
0otherwise

◆ SendFullResponse()

int SendFullResponse ( char const *  name,
int  fd 
)

Send a file with the proper HTTP header.

This function searches through the files stored in the system by comphtml If it finds the file, it sends the proper HTTP header and file to the client. If the stored file has embedded dynamic HTML the functions will be filled in.

Parameters
nameName of the file
fdFile descriptor used to send the file
Return values
1if the file was found
0otherwise

◆ SendGifHeader()

void SendGifHeader ( int  sock)

Send a HTML GIF header.

Sends a GIF response header. Can be useful when dynamically creating your own GIF images.

Parameters
sockSocket to send response
Returns
Nothing
See also
SendHTMLHeader(), SendTextHeader(), SendHTMLHeaderWCookie()

◆ SendHTMLHeader()

void SendHTMLHeader ( int  sock)

Send a HTML response header.

Used to build your own HTML response

Parameters
sockSocket to send response
Returns
Nothing
See also
SendHTMLHeaderWCookie(), SendTextHeader(), SendGifHeader()

◆ SendHTMLHeaderWCookie()

void SendHTMLHeaderWCookie ( int  sock,
char *  cookie 
)

Send a HTML response header and cookie.

Sends a header as well as a cookie to be stored by the client browser.

Parameters
sockSocket to send response
cookiePointer to the cookie
Returns
Nothing
See also
SendHTMLHeader(), SendGifHeader(), SendTextHeader()

◆ SendTextHeader()

void SendTextHeader ( int  sock)

Send a HTML plain text header.

Use as the first part of building your own plain text response.

Parameters
sockSocket to send response
Returns
Nothing
See also
SendHTMLHeader(), SendGifHeader(), SendHTMLHeaderWCookie()

◆ StartHttp()

void StartHttp ( uint16_t  port)

Start the HTTP web server. Further documentation in the Initialization section Initialization - System Initialization Functions.

If no parameters are specified it will listen on port 80, and enable the configuration mirror feature so an application can create it's own custom configuration web page.

Parameters
portListen port, defaults to port 80
Returns
nothing
See also
StopHttp(), StartHttps()

◆ StartHttps()

void StartHttps ( uint16_t  ssl_port,
uint16_t  http_port 
)

Start the HTTPS secure web server.

If no parameters are specified the web server will listen on ports 443 and 80, and enable the configuration mirror feature so an application can create it's own custom configuration web page. If no user key is installed the default system key will be used.

Default parameter values defined in init.h

Parameters
ssl_portSecure listen port, defaults to port 443
http_portNon-secure listen port, defaults to port 80
Returns
nothing
See also
StartHttp(), StopHttp()

◆ StopHttp()

void StopHttp ( )

Stop the HTTP web server.

Returns
nothing
See also
StartHttp()

◆ writeallsafestring()

int writeallsafestring ( int  fd,
PCSTR  str 
)

Send a string and escape all special characters.

When sending a HTML text response, certain characters (e.g. '<') are interpreted by the browser as formatting. This function properly escapes the text so it will appear as intended.

Parameters
fdFile descriptor used to send response
strString to send
Returns
The number of characters sent