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. | |
void BadRequestResponse | ( | int | sock, |
PCSTR | url, | ||
PCSTR | data | ||
) |
Send a response indicating that the client request itself is faulty in some manner.
sock | Socket to send response |
new_page | The URL of the page to display |
data | An explanation or segment of data to display indicating the fault |
|
inline |
Constructor for HTTP GET callback function.
pUrl | Pointer to the URL to intercept from normal system processing |
pFunction | Pointer to the function to call for the requested URL |
reqType | Type of request to intercept, HTTP Request Types. Default is tGet |
accessGroup | Password group access level |
beforeFiles | true = intercept before checking for a file of the same name false = check for any files of the requested name before intercepting |
1,The | callback function handled the request |
2,The | callback 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. |
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.
sock | The socket the request came in on. |
accessGroup | The user defined acess level for this request. See HtmlPageHandler |
Req | The HTTP request wher one can extract the URL , access type password etc if needed |
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.
sock | The HTTP socket. |
access_level | The access level of the requested resource. |
Req | The HTTP request initiating the callback. |
void ForbiddenResponse | ( | int | sock, |
PCSTR | url | ||
) |
Send a page is forbidden response.
sock | Socket to send response |
new_page | The URL of the page to display |
|
inline |
Custom HTTP POST handler function.
pUrl | Pointer to URL character string |
pCallback | Pointer to callback function that will process the POST |
accessGroup | Password group access |
1 | if no errors occurred |
0 | otherwise |
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.
str1 | The string to search |
strIsUpper2 | The string to search for, must be specified in upper case |
0 | if the prefixes do not match |
1 | if the prefixes match |
Example: httpstricmp( str1, "LED.HTML");
str1 | Return Value |
LED | 1 |
led.HTML | 1 |
led.html | 1 |
LED.HTM? | 0 |
void NotAvailableResponse | ( | int | sock, |
PCSTR | url | ||
) |
Send a response indicating that the requested resource is not available at this time.
sock | Socket to send response |
new_page | The URL of the page to display |
void NotFoundResponse | ( | int | sock, |
PCSTR | new_page | ||
) |
Send a page not found response.
sock | Socket to send response |
new_page | The URL of the page to display |
void RedirectResponse | ( | int | sock, |
PCSTR | new_page | ||
) |
Redirect a HTTP request to a different page.
sock | Socket to send response |
new_page | The URL of the new page |
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.
sock | The socket used to send the request |
name | The name that will appear in the password request |
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.
name | Name of the file |
fd | File descriptor used to send the file fragment |
url | Optional URL |
1 | if the file was found |
0 | otherwise |
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.
name | Name of the file |
fd | File descriptor used to send the file |
1 | if the file was found |
0 | otherwise |
void SendGifHeader | ( | int | sock | ) |
Send a HTML GIF header.
Sends a GIF response header. Can be useful when dynamically creating your own GIF images.
sock | Socket to send response |
void SendHTMLHeader | ( | int | sock | ) |
Send a HTML response header.
Used to build your own HTML response
sock | Socket to send response |
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.
sock | Socket to send response |
cookie | Pointer to the cookie |
void SendTextHeader | ( | int | sock | ) |
Send a HTML plain text header.
Use as the first part of building your own plain text response.
sock | Socket to send response |
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.
port | Listen port, defaults to port 80 |
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
ssl_port | Secure listen port, defaults to port 443 |
http_port | Non-secure listen port, defaults to port 80 |
void StopHttp | ( | ) |
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.
fd | File descriptor used to send response |
str | String to send |