Micro hypertext transfer protocol library. More...
Data Structures | |
struct | _HTTP_STREAM |
Stream information structure for Winsock implementations. More... | |
struct | _HTTP_REQUEST |
HTTP request information structure. More... | |
struct | _HTTPD_SESSION |
HTTP session information structure. More... | |
Modules | |
Modules | |
Environment variables | |
Media types | |
Stream I/O | |
Utilities | |
Defines | |
#define | HTTP_ASSERT NUTASSERT |
#define | HTTP_MAJOR_VERSION 1 |
#define | HTTP_MINOR_VERSION 1 |
#define | HTTP_VERSION 0x11 |
#define | HTTP_ROOT (http_root ? http_root : HTTP_DEFAULT_ROOT) |
Typedefs | |
typedef struct _HTTP_REQUEST | HTTP_REQUEST |
HTTP request information structure type. | |
typedef struct _HTTPD_SESSION | HTTPD_SESSION |
HTTP session information structure type. | |
typedef int(* | HTTP_AUTH_VALIDATOR )(HTTPD_SESSION *) |
HTTP authentication function type. | |
typedef int(* | HTTP_LOC_REDIRECTOR )(HTTPD_SESSION *) |
HTTP redirection function type. | |
Functions | |
int | HttpRegisterRootPath (char *path) |
Register the HTTP server's root directory. | |
int | HttpParseHeader (HTTPD_SESSION *hs) |
Parse HTTP header. | |
int | HttpParseMultipartHeader (HTTPD_SESSION *hs, const char *bnd, long *avail) |
Parse HTTP multipart header. | |
void | HttpSendHeaderTop (HTTPD_SESSION *hs, int status) |
Send initial HTTP response header. | |
void | HttpSendHeaderDate (HTTPD_SESSION *hs, time_t mtime) |
Send HTTP date response header. | |
void | HttpSendHeaderBottom (HTTPD_SESSION *hs, char *type, char *subtype, long bytes) |
Send final HTTP response header. | |
void | HttpSendError (HTTPD_SESSION *hs, int status) |
Send HTTP error response. | |
int | HttpSendRedirection (HTTPD_SESSION *hs, int code,...) |
Send HTTP redirection response. | |
char * | HttpArgParseFirst (HTTP_REQUEST *req) |
Get first argument from an HTTP request line. | |
char * | HttpArgParseNext (HTTP_REQUEST *req) |
Get next argument from an HTTP request line. | |
char * | HttpArgReadNext (HTTPD_SESSION *hs, long *avail) |
Read next argument from an HTTP post request. | |
char * | HttpArgValue (HTTP_REQUEST *req) |
Get value of the last read argument. | |
const char * | HttpArgValueSub (const char *str, const char *name, int *len) |
Retrieve parameter value from HTTP header line. | |
void | HttpdClientHandler (HTTP_STREAM *sp) |
Default client handler. | |
Variables | |
int | _HTTP_STREAM::strm_ipos |
int | _HTTP_STREAM::strm_ilen |
char | _HTTP_STREAM::strm_ibuf [1460+128] |
TCPSOCKET * | _HTTP_STREAM::strm_sock |
char * | http_root |
HTTP_AUTH_VALIDATOR | httpd_auth_validator |
HTTP authentication function pointer. | |
HTTP_LOC_REDIRECTOR | httpd_loc_redirector |
HTTP redirection function pointer. | |
HTTP request methods | |
#define | HTTP_METHOD_GET 1 |
Get method. | |
#define | HTTP_METHOD_POST 2 |
Post method. | |
#define | HTTP_METHOD_HEAD 3 |
Head method. | |
HTTP connection types | |
#define | HTTP_CONN_CLOSE 1 |
Connection will be closed. | |
#define | HTTP_CONN_KEEP_ALIVE 2 |
Connection will not be closed. | |
HTTP static texts | |
const char | ct_GET [] |
const char | ct_HEAD [] |
const char | ct_POST [] |
const char | ct_Content_Disposition [] |
const char | ct_Content_Type [] |
const char | ct_Accept_Encoding [] |
const char | ct_Authorization [] |
const char | ct_Connection [] |
const char | ct_close [] |
const char | ct_Keep_Alive [] |
const char | ct_Content_Length [] |
const char | ct_Cookie [] |
const char | ct_Host [] |
const char | ct_Referer [] |
const char | ct_User_Agent [] |
const char | ct_Content_Encoding [] |
const char | ct_Location [] |
const char | ct_If_Modified_Since [] |
const char | ct_Last_Modified [] |
const char | ct_Expires [] |
const char | ct_Date [] |
Micro hypertext transfer protocol library.
This is the second version of a HTTP library for Nut/OS. It has been introduced in Nut/OS 5.0 and may later replace the original HTTP library.
The main advantage of this new version is its flexibility, which not only allows to replace almost any default behavior, but also offers various ways to extend its capabilities without modification of the original source code. To give an example: The list of hard coded media types can be configured with the Nut/OS Configurator. Furthermore, new media types may be either added to this list to be processed by a default handler or may be processed by an application specific handler. In the old library new media types had to be added to the hard coded default list, modifying the original source code.
Operating system (Nut/OS) dependent functions are no longer scattered in the source code. Instead, they are collected in a single module, which makes porting the library to other operating systems quite easy. So far the code had been successfully tested on Windows and a Linux port will probably follow some day.
#define HTTP_ASSERT NUTASSERT |
#define HTTP_MAJOR_VERSION 1 |
Referenced by HttpSendHeaderTop().
#define HTTP_MINOR_VERSION 1 |
Referenced by HttpSendHeaderTop().
#define HTTP_VERSION 0x11 |
#define HTTP_METHOD_GET 1 |
Get method.
Referenced by HttpParseHeader(), HttpSessionInfo(), and HttpSsiExecHandler().
#define HTTP_METHOD_POST 2 |
Post method.
Referenced by HttpParseHeader(), and HttpSessionInfo().
#define HTTP_METHOD_HEAD 3 |
Head method.
Referenced by HttpParseHeader(), and HttpSessionInfo().
#define HTTP_CONN_CLOSE 1 |
Connection will be closed.
#define HTTP_CONN_KEEP_ALIVE 2 |
Connection will not be closed.
Referenced by HttpCgiFunctionHandler(), HttpdClientHandler(), HttpSessionInfo(), and HttpSsiIncludeHandler().
typedef struct _HTTP_REQUEST HTTP_REQUEST |
HTTP request information structure type.
typedef struct _HTTPD_SESSION HTTPD_SESSION |
HTTP session information structure type.
typedef int(* HTTP_AUTH_VALIDATOR)(HTTPD_SESSION *) |
HTTP authentication function type.
typedef int(* HTTP_LOC_REDIRECTOR)(HTTPD_SESSION *) |
HTTP redirection function type.
int HttpRegisterRootPath | ( | char * | path | ) |
Register the HTTP server's root directory.
Only one root directory is supported. Subsequent calls will override previous settings.
path | Absolute path name of the root directory. If NULL, then the path will be reset to the configured default. |
References free(), http_root, NULL, and strdup().
int HttpParseHeader | ( | HTTPD_SESSION * | hs | ) |
Parse HTTP header.
hs | Pointer to the session info structure. |
References atol(), ct_Accept_Encoding, ct_Authorization, ct_close, ct_Connection, ct_Content_Length, ct_Content_Type, ct_Cookie, ct_GET, ct_HEAD, ct_Host, ct_If_Modified_Since, ct_Keep_Alive, ct_POST, ct_Referer, ct_User_Agent, free(), HTTP_CONN_CLOSE, HTTP_CONN_KEEP_ALIVE, HTTP_MAX_REQUEST_SIZE, HTTP_METHOD_GET, HTTP_METHOD_HEAD, HTTP_METHOD_POST, HttpSendError(), malloc(), memset(), NULL, _HTTP_REQUEST::req_agent, _HTTP_REQUEST::req_auth, _HTTP_REQUEST::req_connection, _HTTP_REQUEST::req_cookie, _HTTP_REQUEST::req_encoding, _HTTP_REQUEST::req_host, _HTTP_REQUEST::req_ims, _HTTP_REQUEST::req_length, _HTTP_REQUEST::req_method, _HTTP_REQUEST::req_query, _HTTP_REQUEST::req_referer, _HTTP_REQUEST::req_type, _HTTP_REQUEST::req_url, _HTTP_REQUEST::req_version, RfcTimeParse(), _HTTPD_SESSION::s_req, _HTTPD_SESSION::s_stream, strcasecmp, strchr(), strdup(), StreamReadUntilChars(), strncasecmp, and UriUnescape().
Referenced by HttpdClientHandler().
int HttpParseMultipartHeader | ( | HTTPD_SESSION * | hs, |
const char * | bnd, | ||
long * | avail | ||
) |
Parse HTTP multipart header.
hs | Pointer to the session info structure. |
References ct_Content_Disposition, ct_Content_Type, free(), HTTP_MAX_REQUEST_SIZE, malloc(), MIN, NULL, rc, _HTTP_REQUEST::req_bnd_dispo, _HTTP_REQUEST::req_bnd_type, _HTTPD_SESSION::s_req, _HTTPD_SESSION::s_stream, strcasecmp, strdup(), StreamReadUntilChars(), strlen(), and strncmp().
void HttpSendHeaderTop | ( | HTTPD_SESSION * | hs, |
int | status | ||
) |
Send initial HTTP response header.
hs | Pointer to the session info structure. |
References ct_Date, gmtime(), HTTP_MAJOR_VERSION, HTTP_MINOR_VERSION, HttpResponseText(), NULL, Rfc1123TimeString(), s_printf(), _HTTPD_SESSION::s_stream, s_vputs(), and time().
Referenced by HttpSendError(), HttpSendRedirection(), HttpSsiHandler(), and MediaTypeHandlerBinary().
void HttpSendHeaderDate | ( | HTTPD_SESSION * | hs, |
time_t | mtime | ||
) |
Send HTTP date response header.
hs | Pointer to the session info structure. |
References ct_Last_Modified, gmtime(), NULL, Rfc1123TimeString(), _HTTPD_SESSION::s_stream, and s_vputs().
Referenced by MediaTypeHandlerBinary().
void HttpSendHeaderBottom | ( | HTTPD_SESSION * | hs, |
char * | type, | ||
char * | subtype, | ||
long | bytes | ||
) |
Send final HTTP response header.
hs | Pointer to the session info structure. |
References ct_Content_Length, ct_Content_Type, GZIP_ID, HTTP_CONN_CLOSE, HTTP_CONN_KEEP_ALIVE, NULL, _HTTP_REQUEST::req_connection, s_printf(), s_puts(), _HTTPD_SESSION::s_req, _HTTPD_SESSION::s_stream, and s_vputs().
Referenced by HttpSendError(), HttpSendRedirection(), HttpSsiHandler(), and MediaTypeHandlerBinary().
void HttpSendError | ( | HTTPD_SESSION * | hs, |
int | status | ||
) |
Send HTTP error response.
hs | Pointer to the session info structure. |
References HttpResponseText(), HttpSendHeaderBottom(), HttpSendHeaderTop(), _HTTP_REQUEST::req_realm, s_flush(), s_printf(), _HTTPD_SESSION::s_req, _HTTPD_SESSION::s_stream, and strlen().
Referenced by HttpdClientHandler(), HttpParseHeader(), HttpSsiHandler(), and MediaTypeHandlerBinary().
int HttpSendRedirection | ( | HTTPD_SESSION * | hs, |
int | code, | ||
... | |||
) |
Send HTTP redirection response.
hs | Pointer to the session info structure. |
References ct_Location, free(), HttpSendHeaderBottom(), HttpSendHeaderTop(), malloc(), NULL, s_flush(), s_printf(), _HTTPD_SESSION::s_stream, s_vputs(), strcat(), and strlen().
Referenced by HttpLocationRedir().
char* HttpArgParseFirst | ( | HTTP_REQUEST * | req | ) |
Get first argument from an HTTP request line.
The function returns the name only. Use HttpArgValue() to retrieve its value.
req | Pointer to the request information structure. |
References HttpArgParseNext(), _HTTP_REQUEST::req_argp, and _HTTP_REQUEST::req_query.
char* HttpArgParseNext | ( | HTTP_REQUEST * | req | ) |
Get next argument from an HTTP request line.
req | Pointer to the request information structure. |
References free(), HttpUrlUnescape(), malloc(), memcpy(), NULL, _HTTP_REQUEST::req_argn, _HTTP_REQUEST::req_argp, _HTTP_REQUEST::req_argv, strchr(), and strdup().
Referenced by HttpArgParseFirst().
char* HttpArgReadNext | ( | HTTPD_SESSION * | hs, |
long * | avail | ||
) |
Read next argument from an HTTP post request.
The function returns a pointer to the name. Use HttpArgValue() to retrieve its value.
hs | Pointer to the session info structure. |
avail | Pointer to the variable that contains the number of bytes available in the request body. It will be updated by this function. |
References free(), HttpUrlUnescape(), malloc(), NULL, _HTTP_REQUEST::req_argn, _HTTP_REQUEST::req_argv, _HTTPD_SESSION::s_req, _HTTPD_SESSION::s_stream, strchr(), strdup(), and StreamReadUntilChars().
char* HttpArgValue | ( | HTTP_REQUEST * | req | ) |
Get value of the last read argument.
Returns the value of an argument previously read by HttpArgParseFirst(), HttpArgParseNext() or HttpArgReadNext().
req | Pointer to the request information structure. |
References _HTTP_REQUEST::req_argv.
const char* HttpArgValueSub | ( | const char * | str, |
const char * | name, | ||
int * | len | ||
) |
Retrieve parameter value from HTTP header line.
A HTTP header line may contain a list of parameter name/value pairs, separated by semicolons.
<header-name>: <param-name>="<param-value>"; <param-name>="<param-value>"..
This function can be used to retrieve a value of a parameter that is specified by its name. Surrounding quotation marks are excluded from the result.
str | Pointer to the text buffer that contains the header line. |
name | Name of the parameter to retrieve. |
len | Pointer to a variable that receives the length of the value. |
References NULL, strchr(), strlen(), and strncasecmp.
void HttpdClientHandler | ( | HTTP_STREAM * | sp | ) |
Default client handler.
sp | Pointer to the stream's information structure. |
References AllocConcatStrings(), free(), GetMediaTypeEntry(), HTTP_CONN_KEEP_ALIVE, HTTP_ROOT, httpd_auth_validator, httpd_loc_redirector, HttpParseHeader(), HttpSendError(), malloc(), _MEDIATYPE::media_handler, NULL, _HTTP_REQUEST::req_agent, _HTTP_REQUEST::req_argn, _HTTP_REQUEST::req_argp, _HTTP_REQUEST::req_auth, _HTTP_REQUEST::req_bnd_dispo, _HTTP_REQUEST::req_bnd_type, _HTTP_REQUEST::req_connection, _HTTP_REQUEST::req_cookie, _HTTP_REQUEST::req_encoding, _HTTP_REQUEST::req_host, _HTTP_REQUEST::req_query, _HTTP_REQUEST::req_realm, _HTTP_REQUEST::req_referer, _HTTP_REQUEST::req_type, _HTTP_REQUEST::req_url, _HTTPD_SESSION::s_req, and _HTTPD_SESSION::s_stream.
Referenced by StreamReadUntilChars(), and StreamReadUntilString().
Referenced by StreamReadUntilChars(), and StreamReadUntilString().
Referenced by StreamReadUntilChars(), and StreamReadUntilString().
Referenced by s_flush(), s_printf(), s_puts(), s_vputs(), s_write(), StreamClientAccept(), StreamReadUntilChars(), and StreamReadUntilString().
const char ct_GET[] |
Constant string "GET".
Referenced by HttpParseHeader(), and HttpSessionInfo().
const char ct_HEAD[] |
Constant string "HEAD".
Referenced by HttpParseHeader(), and HttpSessionInfo().
const char ct_POST[] |
Constant string "POST".
Referenced by HttpParseHeader(), and HttpSessionInfo().
const char ct_Content_Disposition[] |
Constant string "Content-Disposition".
Referenced by HttpParseMultipartHeader().
const char ct_Content_Type[] |
Constant string "Content-Type".
Referenced by HttpParseHeader(), HttpParseMultipartHeader(), and HttpSendHeaderBottom().
const char ct_Accept_Encoding[] |
Constant string "Accept-Encoding".
Referenced by HttpParseHeader().
const char ct_Authorization[] |
Constant string "Authorization".
Referenced by HttpParseHeader().
const char ct_Connection[] |
Constant string "Connection".
Referenced by HttpParseHeader().
const char ct_close[] |
Constant string "close".
Referenced by HttpParseHeader(), and HttpSessionInfo().
const char ct_Keep_Alive[] |
Constant string "keep-alive".
Referenced by HttpParseHeader(), and HttpSessionInfo().
const char ct_Content_Length[] |
Constant string "Content-Length".
Referenced by HttpParseHeader(), and HttpSendHeaderBottom().
const char ct_Cookie[] |
Constant string "Cookie".
Referenced by HttpParseHeader().
const char ct_Host[] |
Constant string "Host".
Referenced by HttpParseHeader().
const char ct_Referer[] |
Constant string "Referer".
Referenced by HttpParseHeader().
const char ct_User_Agent[] |
Constant string "User-Agent".
Referenced by HttpParseHeader().
const char ct_Content_Encoding[] |
Constant string "Content-Encoding".
const char ct_Location[] |
Constant string "Location".
Referenced by HttpSendRedirection().
const char ct_If_Modified_Since[] |
Constant string "If-Modified-Since".
Referenced by HttpParseHeader().
const char ct_Last_Modified[] |
Constant string "Last-Modified".
Referenced by HttpSendHeaderDate().
const char ct_Expires[] |
Constant string "Expires".
Referenced by HttpSsiHandler().
const char ct_Date[] |
Constant string "Date".
Referenced by HttpSendHeaderTop().
char* http_root |
Referenced by CreateFilePath(), and HttpRegisterRootPath().
HTTP authentication function pointer.
Referenced by HttpdClientHandler(), and HttpRegisterAuthBasic().
HTTP redirection function pointer.
Referenced by HttpdClientHandler(), and HttpRegisterRedir().