![]() |
WL865E4-P
36.07.001
|
This section describes the M2MB APIs to perform HTTP server operations. More...
This section describes the M2MB APIs to perform HTTP server operations.
#define M2MB_HTTPD_PATH_MAX 31 |
Maximum length of path
Definition at line 51 of file m2mb_httpd.h.
#define M2MB_HTTPD_SRVR_NAME_MAX 512 |
Maximum length of Server
Definition at line 52 of file m2mb_httpd.h.
typedef struct M2MB_HTTPD_CONFIG_S M2MB_HTTPD_CONFIG_T |
HTTP server configuration structure.
Structure for storing HTTP server configuration. User will fill this structure and give as input to m2mb_httpd_init API to initialize the HTTP server.
HTTP server URI Request user call back prototype.
Type definition of the user callback to handle the request received on the configured URI using m2mb_httpd_uri_cfg API. event is defined by M2MB_HTTPD_URI_USER_EVENT_E.
Definition at line 248 of file m2mb_httpd.h.
HTTP server CGI form data structure.
Structure containing members representing CGI form data.
typedef struct M2MB_HTTPD_URI_REQ_CGI_KEY_PAIR M2MB_HTTPD_URI_REQ_CGI_KEY_PAIR_T |
HTTP server CGI parameter pair structure.
Structure containing members representing a pair of CGI parameters.
typedef struct M2MB_HTTPD_URI_REQ_INFO M2MB_HTTPD_URI_REQ_INFO_T |
HTTP server URI Request structure.
Structure containing members representing URI request received.
typedef enum M2MB_HTTPD_URI_USER_EVENT M2MB_HTTPD_URI_USER_EVENT_E |
HTTP server URI user event enumeration.
This enum defines macros for type of user events for URI operations.
typedef struct M2MB_HTTPD_URI_CTX M2MB_HTTPD_URICTX_T |
HTTP server URI context structure.
Structure for storing HTTP server URI context related to particular URI.
typedef enum M2MB_URI_AUTH_FLAG M2MB_URI_AUTH_FLAG_T |
HTTP server URI user authentication enumeration.
This enum defines macros for type of user authentication supported for URI.
Return values enumeration.
This enum defines macros for return values of URI callback that are supported by HTTP server.
Enumerator | |
---|---|
FP_ERR | Error |
FP_OK | OK |
FP_FILE | File |
FP_DONE | Done |
Definition at line 61 of file m2mb_httpd.h.
enum M2MB_HTTPD_METHOD_E |
HTTP server request method enumeration.
This enum defines macros for request methods that are supported by HTTP server.
Definition at line 87 of file m2mb_httpd.h.
enum M2MB_HTTPD_MODE_E |
HTTP server operational mode enumeration.
This enum defines macros for operational modes that are supported by HTTP server.
Enumerator | |
---|---|
M2MB_HTTPD_MODE_HTTP | Only nonsecure HTTP. |
M2MB_HTTPD_MODE_HTTPS | Only HTTPS. |
M2MB_HTTPD_MODE_HTTP_AND_HTTPS | Both HTTP and HTTPS. |
Definition at line 75 of file m2mb_httpd.h.
HTTP server URI user event enumeration.
This enum defines macros for type of user events for URI operations.
Definition at line 117 of file m2mb_httpd.h.
enum M2MB_URI_AUTH_FLAG |
HTTP server URI user authentication enumeration.
This enum defines macros for type of user authentication supported for URI.
Enumerator | |
---|---|
M2MB_URI_FLAG_NOAUTH | No authentication |
M2MB_URI_FLAG_AUTHBASIC | check Basic user auth |
M2MB_URI_FLAG_AUTHMD5 | check MD5 user auth |
Definition at line 105 of file m2mb_httpd.h.
M2MB_STATUS_T m2mb_httpd_deinit | ( | ) |
HTTP server initialization.
This API deinitializes HTTP server.
Get URI context from URI's index.
This API gets the URI context stored during the configuring the new URI. For every URI configured, one unique index can be maintained. This API uses the index to get the URI context. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | index | Integer number indicating the index number. |
m2mb_httpd_FindURICtx_FromIndex( index );
Get message body location.
This API gets the location of the message content (body) present in request from the client on a configured URI. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | conn_handle | Pointer representing the HTTP server handle. |
m2mb_httpd_get_content_len( conn_handle );
M2MB_HTTPD_URI_REQ_CGI_FORM_DATA_T* m2mb_httpd_get_cgi_form | ( | VOID * | conn_handle | ) |
Get CGI form data.
This API gets the pointer to the CGI parameters expressed as form data extracted from the request line of the URI request received on HTTP server connection.
[in] | conn_handle | Pointer representing the HTTP server handle. |
m2mb_httpd_get_cgi_form( conn_handle );
Get content length.
This API gets the length of the content present in request from the client on a configured URI. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | conn_handle | Pointer representing the HTTP server handle. |
m2mb_httpd_get_content_len( conn_handle );
M2MB_STATUS_T m2mb_httpd_get_message_body | ( | VOID * | conn_handle, |
INT8 * | buf, | ||
UINT32 * | plen | ||
) |
Get Message Body of URI request.
This API copies the given length of the body of request received on a configured URI to HTTP server to given buffer. If the buffer is NULL then the length of the total body available.
[in] | conn_handle | Pointer representing the HTTP server handle. |
[in] | buf | Buffer to where body from the response from Server to Client should be copied as the content. |
[in] | plen | Pointer to an integer mentioning the length of the content required from the response form Server to Client. |
m2mb_httpd_get_message_body( conn_handle, buffer, pLength );
M2MB_STATUS_T m2mb_httpd_get_message_head | ( | VOID * | conn_handle, |
UINT8 * | buf, | ||
UINT32 * | plen | ||
) |
Get Message header of URI request.
This API copies the given length of header of request received on a configured URI to HTTP server to given buffer. If the buffer is NULL then the length of the total header available.
[in] | conn_handle | Pointer representing the HTTP server handle. |
[in] | buf | Buffer to where header from the response from Server to Client should be copied as the content. |
[in] | plen | Pointer to an integer mentioning the length of the header required from the response form Server to Client. |
m2mb_httpd_get_message_head( hp, buffer, pLength );
Get request type.
This API gets the type of request received from the client on a configured URI. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | conn_handle | Pointer representing the HTTP server handle. |
m2mb_httpd_get_request_type( conn_handle );
M2MB_STATUS_T m2mb_httpd_init | ( | M2MB_HTTPD_CONFIG_T * | cfg, |
M2MB_SSL_CTXT_HANDLE | ssl_handle | ||
) |
HTTP server initialization.
This API configures and initializes HTTP server. It takes the configuration of the server and SSL handle created using m2mb_ssl_init API as the input.
[in] | cfg | User should pass the configuration of HTTP server by using M2MB_HTTPD_CONFIG_T structure. |
[in] | ssl_handle | Handler to SSL created by using m2mb_ssl_init API. |
m2mb_httpd_init( pCfg, ssl_handle );
M2MB_STATUS_T m2mb_httpd_is_started | ( | ) |
Status of HTTP server.
This API gives the running status of HTTP server.
M2MB_STATUS_T m2mb_httpd_send_data | ( | VOID * | conn_handle, |
const INT8 * | data, | ||
UINT32 | length | ||
) |
Send HTTP data.
This API sends the HTTP data to client after receiving request from the client on a configured URI. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | conn_handle | Pointer representing the HTTP server handle. |
[in] | data | Data going in the response from Server to Client as the content. |
[in] | length | An integer mentioning the length of the content going in the response from Server to Client. |
m2mb_httpd_send_http_data( hp, "0123456789", 10 );
M2MB_STATUS_T m2mb_httpd_send_headers | ( | VOID * | conn_handle, |
const INT8 * | content_type, | ||
INT32 | content_length, | ||
INT32 | status_code, | ||
const INT8 * | status_text, | ||
const INT8 * | user_headers | ||
) |
Send HTTP headers.
This API sends the HTTP headers to the client after receiving a request from the client on a configured URI. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).
[in] | conn_handle | Pointer representing the HTTP server handle. |
[in] | content_type | String mentioning the type of content going in the response from Server to Client. |
[in] | content_length | An integer mentioning the length of the content going in the response from Server to Client. |
[in] | status_code | Status code defining the response from the server. Please refer to generic status codes the HTTP server support. |
[in] | status_text | User defined status string corresponding to the status code. |
[in] | user_headers | User defined headers in a string format. Every header should be separated by CR+LF. |
m2mb_httpd_send_headers( hp, "test/plain", 100, 200, "SUCCESS", "" );
M2MB_STATUS_T m2mb_httpd_start | ( | ) |
Start HTTP server.
This API starts HTTP server.
M2MB_STATUS_T m2mb_httpd_stop | ( | ) |
Stop HTTP server.
This API stops HTTP server.
M2MB_OS_RESULT_E m2mb_httpd_uri_cfg | ( | CHAR * | uri, |
UINT8 * | methods, | ||
M2MB_URI_AUTH_FLAG_T | flag, | ||
M2MB_HTTPD_URI_HANDLER_T | fn_cb, | ||
VOID * | usr_ctx | ||
) |
Configure URI to HTTP server.
This API configures given URI to the HTTP server running.
[in] | uri | String representing URI. |
[in] | methods | Methods supported by the URI, it can be a combination of many ET, POST, HEAD. |
[in] | flag | Flag mentioning the type of authentication used for the URI defined by M2MB_URI_AUTH_FLAG_T. |
[in] | fn_cb | User callback to handle the requests to be received on this URI. If CGI, then pointer to a valid function else NULL, for file system. |
[in] | usr_ctx | User callback context to be used in handling the requests to be received on this URI. |
m2mb_httpd_uri_cfg( "test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL );
M2MB_OS_RESULT_E m2mb_httpd_uri_decfg | ( | char * | uri | ) |
De-Configure URI from HTTP server.
This API de-configures a given URI from the HTTP server running.
m2mb_httpd_uri_decfg("test");
M2MB_STATUS_T m2mb_httpd_user_add | ( | const char * | username, |
const char * | password | ||
) |
Add a USER to HTTPD module.
This API adds a USER to HTTPD module.
[in] | username | A NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1. |
[in] | password | A NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1. |
m2mb_httpd_user_add( "admin", "password" );
M2MB_STATUS_T m2mb_httpd_user_change_password | ( | char * | username, |
char * | cur_password, | ||
char * | new_password | ||
) |
Change password of a USER to HTTPD module.
This API changes the password of a USER in HTTPD module.
[in] | username | A NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1. |
[in] | cur_password | A NULL-terminated password string representing current password. The name length cannot be over MAX_USERLENGTH - 1. |
[in] | new_password | A NULL-terminated password string representing new password. The name length cannot be over MAX_USERLENGTH - 1. |
m2mb_httpd_user_validate( "admin", "password", "new_password" );
M2MB_STATUS_T m2mb_httpd_user_del | ( | const char * | username, |
const char * | password | ||
) |
Delete a USER to HTTPD module.
This API deletes a USER from HTTPD module.
[in] | username | A NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1. |
[in] | password | A NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1. |
m2mb_httpd_user_del( "admin", "password" );
M2MB_STATUS_T m2mb_httpd_user_validate | ( | char * | username, |
char * | password | ||
) |
Validate a USER to HTTPD module.
This API validates USER details in HTTPD module.
[in] | username | A NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1. |
[in] | password | A NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1. |
m2mb_httpd_user_validate( "admin", "password" );