Hypertext transfer protocol. More...
Data Structures | |
struct | _REQUEST |
HTTP request information structure. More... | |
struct | _MIMETYPES |
struct | _AUTHINFO |
HTTP authorization information structure. More... | |
struct | _CGIFUNCTION |
Registered CGI function. More... | |
struct | _REQUEST_LOOKUP |
Structure for table of interpreted header names. More... | |
Defines | |
#define | METHOD_GET 1 |
#define | METHOD_POST 2 |
#define | METHOD_HEAD 3 |
#define | HTTP_CONN_CLOSE 1 |
#define | HTTP_CONN_KEEP_ALIVE 2 |
#define | HTTP_OF_USE_HOST_TIME 0x00000001UL |
#define | HTTP_OF_USE_FILE_TIME 0x00000002UL |
#define | MAX_BUFFER_SIZE 256 |
#define | MAX_ASP_FUNC_SIZE 64 |
#define | NUM_REQUEST_LOOKUP sizeof(req_lookup) / sizeof(REQUEST_LOOKUP) |
Number of entries in the header name table. | |
#define | MAX_REQUEST_NAME_SIZE 17 |
Size of the largest entry in the header name table. | |
#define | BUFSIZE 512 |
#define | MIN(a, b) (a<b?a:b) |
#define | SSI_TYPE_FILE 0x01 |
#define | SSI_TYPE_VIRTUAL 0x02 |
#define | SSI_TYPE_EXEC 0x03 |
#define | SSI_TYPE_ECHO 0x04 |
Typedefs | |
typedef struct _REQUEST | REQUEST |
typedef struct _MIMETYPES | MIMETYPES |
typedef typedef__END_DECLS struct _AUTHINFO | AUTHINFO |
typedef typedef__END_DECLS struct _CGIFUNCTION | CGIFUNCTION |
typedef struct _REQUEST_LOOKUP | REQUEST_LOOKUP |
Structure for table of interpreted header names. | |
Enumerations | |
enum | { ASP_STATE_IDLE = 0, ASP_STATE_START, ASP_STATE_COPY_FUNC } |
Functions | |
void | NutHttpProcessRequest (FILE *stream) |
Process the next HTTP request. | |
void | NutHttpProcessQueryString (REQUEST *req) |
Parses the QueryString. | |
void | NutHttpSendHeaderTop (FILE *stream, REQUEST *req, int status, char *title) |
Send top lines of a standard HTML header. | |
void | NutHttpSendHeaderBottom (FILE *stream, REQUEST *req, char *mime_type, long bytes) |
Send bottom lines of a standard HTML header. | |
void | NutHttpSendHeaderBot (FILE *stream, char *mime_type, long bytes) |
Send bottom lines of a standard HTML header. | |
void | NutHttpSendError (FILE *stream, REQUEST *req, int status) |
Send a HTTP error response. | |
char * | NutGetMimeType (char *name) |
Return the mime type description of a specified file name. | |
void * | NutGetMimeHandler (char *name) |
Return the mime type handler of a specified file name. | |
uint8_t | NutSetMimeHandler (char *extension, void(*handler)(FILE *stream, int fd, int file_len, char *http_root, REQUEST *req)) |
Set the mime type handler for a specified file extension. | |
int | NutHttpAuthValidate (REQUEST *req) |
Validate an authorization request. | |
int | NutRegisterAuth (CONST char *dirname, CONST char *login) |
Register an authorization entry. | |
void | NutClearAuth (void) |
Clear all authorization entries. | |
void | NutRegisterSsi (void) |
Register SSI handler for shtml files. | |
void | NutHttpProcessAsp (FILE *stream, int fd, int file_len, char *http_root, REQUEST *req) |
int | NutRegisterAspCallback (int(*func)(char *, FILE *)) |
void | NutRegisterAsp (void) |
Register ASP handler for asp files. | |
void | NutRegisterCgiBinPath (char *path) |
Register a new cgi-bin path. | |
int | NutCgiCheckRequest (FILE *stream, REQUEST *req) |
Check if request is a cgi call. | |
int | NutRegisterCgi (char *name, int(*func)(FILE *, REQUEST *)) |
Register a CGI function. | |
void | NutCgiProcessRequest (FILE *stream, REQUEST *req, int name_pos) |
Process an incoming CGI request. | |
void | NutHttpURLDecode (char *str) |
URLDecodes a string. | |
int | NutRegisterHttpRoot (char *path) |
Register the HTTP server's root directory. | |
void | NutHttpSetOptionFlags (uint32_t flags) |
Set HTTP option flags. | |
uint32_t | NutHttpGetOptionFlags (void) |
Retrieve HTTP option flags. | |
char * | NutHttpURLEncode (char *str) |
URLEncodes a string. | |
void | NutHttpProcessPostQuery (FILE *stream, REQUEST *req) |
Parses the QueryString. | |
char * | NutHttpGetParameter (REQUEST *req, char *name) |
Gets a request parameter value by name. | |
int | NutHttpGetParameterCount (REQUEST *req) |
Gets the number of request parameters. | |
char * | NutHttpGetParameterName (REQUEST *req, int index) |
Gets the name of a request parameter. | |
char * | NutHttpGetParameterValue (REQUEST *req, int index) |
Get the value of a request parameter. | |
int | NutRegisterSsiVarHandler (char *(*handler)(char *name, REQUEST *req)) |
Register SSI handler for variables. | |
Variables | |
CONFNET | confnet |
Global network configuration structure. | |
AUTHINFO * | authList = 0 |
CGIFUNCTION *volatile | cgiFunctionList = 0 |
char * | cgiBinPath = NULL |
MIMETYPES | mimeTypes [] |
Known mime types. | |
MIMETYPES | mimeTypes [] |
Known mime types. | |
char * | http_root |
char * | cgiBinPath |
Hypertext transfer protocol.
A read-only file system is sufficient to run an HTTP server.
#define METHOD_GET 1 |
Definition at line 92 of file httpd.h.
Referenced by NutCgiProcessRequest(), and NutHttpProcessRequest().
#define METHOD_POST 2 |
Definition at line 93 of file httpd.h.
Referenced by NutCgiProcessRequest(), NutHttpProcessPostQuery(), and NutHttpProcessRequest().
#define METHOD_HEAD 3 |
Definition at line 94 of file httpd.h.
Referenced by NutHttpProcessRequest().
#define HTTP_CONN_CLOSE 1 |
Definition at line 96 of file httpd.h.
Referenced by NutHttpProcessRequest(), and NutHttpSendError().
#define HTTP_CONN_KEEP_ALIVE 2 |
Definition at line 97 of file httpd.h.
Referenced by NutHttpProcessRequest().
#define HTTP_OF_USE_HOST_TIME 0x00000001UL |
Definition at line 99 of file httpd.h.
Referenced by NutHttpSendHeaderTop().
#define MAX_BUFFER_SIZE 256 |
Definition at line 92 of file asp.c.
Referenced by NutHttpProcessAsp().
#define MAX_ASP_FUNC_SIZE 64 |
Definition at line 98 of file asp.c.
Referenced by NutHttpProcessAsp().
#define NUM_REQUEST_LOOKUP sizeof(req_lookup) / sizeof(REQUEST_LOOKUP) |
#define MAX_REQUEST_NAME_SIZE 17 |
typedef struct _MIMETYPES MIMETYPES |
typedef typedef__END_DECLS struct _CGIFUNCTION CGIFUNCTION |
typedef struct _REQUEST_LOOKUP REQUEST_LOOKUP |
Structure for table of interpreted header names.
anonymous enum |
void NutHttpProcessRequest | ( | FILE * | stream | ) |
Process the next HTTP request.
Waits for the next HTTP request on an established connection and processes it.
stream | Stream of the socket connection, previously opened for binary read and write. |
Definition at line 1054 of file httpd.c.
References DestroyRequestInfo(), fflush(), fgets(), free(), HTTP_CONN_CLOSE, HTTP_CONN_KEEP_ALIVE, HTTP_KEEP_ALIVE_REQ, HTTP_MAX_REQUEST_SIZE, malloc(), METHOD_GET, METHOD_HEAD, METHOD_POST, NutDecodePath(), NutHttpProcessQueryString(), NutHttpSendError(), _REQUEST::req_connection, _REQUEST::req_method, _REQUEST::req_query, _REQUEST::req_url, _REQUEST::req_version, strcasecmp, strchr(), and strdup().
Referenced by main(), and Service().
void NutHttpProcessQueryString | ( | REQUEST * | req | ) |
Parses the QueryString.
Reads the QueryString from a request, and parses it into name/value table. To save RAM, this method overwrites the contents of req_query, and creates a table of pointers into the req_query buffer.
req | Request object to parse |
Definition at line 548 of file httpd.c.
References malloc(), NutHttpURLDecode(), _REQUEST::req_numqptrs, _REQUEST::req_qptrs, and _REQUEST::req_query.
Referenced by NutHttpProcessRequest().
Send top lines of a standard HTML header.
Sends HTTP and Server version lines.
stream | Stream of the socket connection, previously opened for binary read and write. |
req | The associated client request. |
status | Response status, error code or 200, if no error occurred. |
title | Error text, or OK, if no error occurred. |
Definition at line 294 of file httpd.c.
References fprintf(), fprintf_P, gmtime(), HTTP_MAJOR_VERSION, HTTP_MINOR_VERSION, HTTP_OF_USE_HOST_TIME, NutVersionString(), prog_char, Rfc1123TimeString(), and time().
Referenced by NutHttpSendError(), and ShowForm().
Send bottom lines of a standard HTML header.
Sends Content-Type, Content-Lenght and Connection lines.
stream | Stream of the socket connection, previously opened for binary read and write. |
mime_type | Points to a string that specifies the content type. Examples are "text/html", "image/png", "image/gif", "video/mpeg" or "text/css". A null pointer is ignored. |
bytes | Content length of the data following this header. Ignored, if negative. |
Definition at line 388 of file httpd.c.
Referenced by NutHttpSendError(), NutHttpSendHeaderBot(), and ShowForm().
void NutHttpSendHeaderBot | ( | FILE * | stream, |
char * | mime_type, | ||
long | bytes | ||
) |
Send bottom lines of a standard HTML header.
Sends Content-Type and Content-Length.
stream | Stream of the socket connection, previously opened for binary read and write. |
mime_type | Points to a string that specifies the content type. Examples are "text/html", "image/png", "image/gif", "video/mpeg" or "text/css". A null pointer is ignored. |
bytes | Content length of the data following this header. Ignored, if negative. |
Definition at line 323 of file httpd.c.
References NutHttpSendHeaderBottom().
Send a HTTP error response.
A canned error file is used.
stream | Stream of the socket connection, previously opened for binary read and write. |
req | Contains the HTTP request. |
status | Error code to be returned. |
Definition at line 403 of file httpd.c.
References fprintf_P, HTTP_CONN_CLOSE, NutHttpSendHeaderBottom(), NutHttpSendHeaderTop(), prog_char, _REQUEST::req_connection, _REQUEST::req_url, and strrchr().
Referenced by NutCgiProcessRequest(), and NutHttpProcessRequest().
char * NutGetMimeType | ( | char * | name | ) |
Return the mime type description of a specified file name.
The mime type returned is based on the file extension.
name | Name of the file. |
Definition at line 483 of file httpd.c.
References _MIMETYPES::mtyp_type.
void * NutGetMimeHandler | ( | char * | name | ) |
Return the mime type handler of a specified file name.
This is the function that handles / sends a specific file type to the client. Specially used for server side includes (shtml files)
name | Name of the file. |
Definition at line 503 of file httpd.c.
References _MIMETYPES::mtyp_handler.
uint8_t NutSetMimeHandler | ( | char * | extension, |
void(*)(FILE *stream, int fd, int file_len, char *http_root, REQUEST *req) | handler | ||
) |
Set the mime type handler for a specified file extension.
This is the function that handles / sends a specific file type to the client. Specially used for server side includes (shtml files)
extension | Filename extension the handler should be registered for |
handler | pointer to a function of the type void (u_char filename) |
Definition at line 93 of file httpopt.c.
References _MIMETYPES::mtyp_ext, _MIMETYPES::mtyp_handler, and strcasecmp.
Referenced by NutRegisterAsp(), and NutRegisterSsi().
int NutHttpAuthValidate | ( | REQUEST * | req | ) |
Validate an authorization request.
req | Request to be checked. |
Definition at line 170 of file auth.c.
References NutDecodeBase64(), _REQUEST::req_auth, _REQUEST::req_url, strncmp(), and strrchr().
int NutRegisterAuth | ( | CONST char * | dirname, |
CONST char * | login | ||
) |
Register an authorization entry.
Protect a specified directory from unauthorized access.
dirname | Name of the directory to protect. |
login | Required login to access this directory. This string must contain a user name, followed by a colon followed by an uncrypted password. |
Definition at line 116 of file auth.c.
References authList, free(), malloc(), and strdup().
Referenced by main().
void NutClearAuth | ( | void | ) |
void NutRegisterSsi | ( | void | ) |
Register SSI handler for shtml files.
shtml files may use the following ssi commands:
Definition at line 575 of file ssi.c.
References NutSetMimeHandler().
Referenced by main().
Definition at line 160 of file asp.c.
References _filelength(), _read(), ASP_STATE_COPY_FUNC, ASP_STATE_IDLE, ASP_STATE_START, free(), fwrite(), malloc(), MAX_ASP_FUNC_SIZE, and MAX_BUFFER_SIZE.
Referenced by NutRegisterAsp().
int NutRegisterAspCallback | ( | int(*)(char *, FILE *) | func | ) |
void NutRegisterAsp | ( | void | ) |
Register ASP handler for asp files.
asp files may use the following syntax:
<my_function%>
Definition at line 332 of file asp.c.
References NutHttpProcessAsp(), and NutSetMimeHandler().
Referenced by main().
void NutRegisterCgiBinPath | ( | char * | path | ) |
Check if request is a cgi call.
This functions checks the request if it's a cgi all and in case calls the cgi
stream | Stream of the socket connection, previously opened for binary read and write. |
req | Contains the HTTP request. |
Definition at line 116 of file cgi.c.
References cgiBinPath, CONST, NutCgiProcessRequest(), _REQUEST::req_url, and strncasecmp.
Register a CGI function.
name | Name of this CGI function. No dublicates allowed |
func | The function to be called, if the client requests the specified name. |
Definition at line 155 of file cgi.c.
References cgiFunctionList, malloc(), strcmp(), and strdup().
Referenced by main(), and upnp_Init().
Process an incoming CGI request.
Applications do not need to call this function. It is automatically called by NutHttpProcessRequest().
stream | Stream of the socket connection, previously opened for binary read and write. |
req | Contains the HTTP request. |
Definition at line 190 of file cgi.c.
References cgiFunctionList, METHOD_GET, METHOD_POST, NutHttpSendError(), _REQUEST::req_method, _REQUEST::req_url, and strcasecmp.
Referenced by NutCgiCheckRequest().
void NutHttpURLDecode | ( | char * | str | ) |
URLDecodes a string.
Takes a url-encoded string and decodes it.
str | String to decode. This is overwritten with the decoded string |
Definition at line 519 of file httpd.c.
References strtol().
Referenced by NutHttpProcessPostQuery(), and NutHttpProcessQueryString().
int NutRegisterHttpRoot | ( | char * | path | ) |
Register the HTTP server's root directory.
Only one root directory is supported. Subsequent calls will override previous settings.
path | Pathname of the root directory. Must include the device name followed by a colon followed by a directory path followed by a trailing slash. |
Definition at line 775 of file httpd.c.
References free(), malloc(), strcpy(), and strlen().
Referenced by main().
void NutHttpSetOptionFlags | ( | uint32_t | flags | ) |
uint32_t NutHttpGetOptionFlags | ( | void | ) |
char* NutHttpURLEncode | ( | char * | str | ) |
URLEncodes a string.
str | String to encode |
Definition at line 117 of file httpopt.c.
References malloc(), and strlen().
Parses the QueryString.
Reads the query from input stream and parses it into name/value table. To save RAM, this method allocated ram and uses req_query to store the input data. Then it creates a table of pointers into the req_query buffer.
stream | Input stream |
req | Request object to parse |
Definition at line 166 of file httpopt.c.
References fread(), free(), malloc(), memset(), METHOD_POST, NutHttpURLDecode(), _REQUEST::req_length, _REQUEST::req_method, _REQUEST::req_numqptrs, _REQUEST::req_qptrs, and _REQUEST::req_query.
char* NutHttpGetParameter | ( | REQUEST * | req, |
char * | name | ||
) |
Gets a request parameter value by name.
req | Request object |
name | Name of parameter |
Definition at line 244 of file httpopt.c.
References _REQUEST::req_numqptrs, _REQUEST::req_qptrs, and strcmp().
int NutHttpGetParameterCount | ( | REQUEST * | req | ) |
Gets the number of request parameters.
The following code fragment retrieves all name/value pairs of the request.
#include <pro/httpd.h> char *name; char *value; int i; int n = NutHttpGetParameterCount(req); for (i = 0; i < n; i++) { name = NutHttpGetParameterName(req, i); value = NutHttpGetParameterValue(req, i); }
req | Request object |
Definition at line 277 of file httpopt.c.
References _REQUEST::req_numqptrs.
Referenced by NutHttpGetParameterName(), NutHttpGetParameterValue(), and ShowForm().
char* NutHttpGetParameterName | ( | REQUEST * | req, |
int | index | ||
) |
Gets the name of a request parameter.
req | Request object |
index | Index of the requested parameter. |
Definition at line 291 of file httpopt.c.
References NutHttpGetParameterCount(), and _REQUEST::req_qptrs.
Referenced by ShowForm().
char* NutHttpGetParameterValue | ( | REQUEST * | req, |
int | index | ||
) |
Get the value of a request parameter.
req | Request object |
index | Index to the requested parameter. |
Definition at line 307 of file httpopt.c.
References NutHttpGetParameterCount(), and _REQUEST::req_qptrs.
Referenced by ShowForm().
int NutRegisterSsiVarHandler | ( | char *(*)(char *name, REQUEST *req) | handler | ) |
Definition at line 82 of file auth.c.
Referenced by NutClearAuth(), and NutRegisterAuth().
CGIFUNCTION* volatile cgiFunctionList = 0 |
Definition at line 88 of file cgi.c.
Referenced by NutCgiProcessRequest(), and NutRegisterCgi().
char* cgiBinPath = NULL |
Definition at line 89 of file cgi.c.
Referenced by NutCgiCheckRequest(), and NutRegisterCgiBinPath().
{ { ".txt", "text/plain", NULL}, { ".html", "text/html", NULL}, { ".shtml", "text/html", NULL}, { ".asp", "text/html", NULL}, { ".htm", "text/html", NULL}, { ".gif", "image/gif", NULL}, { ".jpg", "image/jpeg", NULL}, { ".png", "image/png", NULL}, { ".bmp", "image/bmp", NULL}, { ".pdf", "application/pdf", NULL}, { ".js", "application/x-javascript", NULL}, { ".jar", "application/x-java-archive", NULL}, { ".css", "text/css", NULL}, { ".xml", "text/xml", NULL}, { ".svg", "image/svg+xml", NULL}, { NULL, NULL, NULL} }
Known mime types.
char* http_root |
Definition at line 33 of file httpd_p.c.
Referenced by CreateFilePath().
char* cgiBinPath |
Definition at line 89 of file cgi.c.
Referenced by NutCgiCheckRequest(), and NutRegisterCgiBinPath().