WL865E4-P  36.07.001
M2MB HTTPD

This section describes the M2MB APIs to perform HTTP server operations. More...

#define M2MB_HTTPD_PATH_MAX   31
 
#define M2MB_HTTPD_SRVR_NAME_MAX   512
 
enum  M2MB_HTTPD_CGI_RETURN_E {
  FP_ERR = 0x110,
  FP_OK = 0x120,
  FP_FILE = 0x140,
  FP_DONE = 0x200
}
 Return values enumeration. More...
 
enum  M2MB_HTTPD_MODE_E {
  M2MB_HTTPD_MODE_HTTP = 1,
  M2MB_HTTPD_MODE_HTTPS = 2,
  M2MB_HTTPD_MODE_HTTP_AND_HTTPS = 3
}
 HTTP server operational mode enumeration. More...
 
enum  M2MB_HTTPD_METHOD_E {
  M2MB_HTTPD_METHOD_INVALID = 1,
  M2MB_HTTPD_METHOD_GET = 2,
  M2MB_HTTPD_METHOD_HEAD = 3,
  M2MB_HTTPD_METHOD_POST = 4,
  M2MB_HTTPD_METHOD_PUT = 5,
  M2MB_HTTPD_METHOD_DELETE = 6,
  M2MB_HTTPD_METHOD_TRACE = 7,
  M2MB_HTTPD_METHOD_POSTMULTI = 8
}
 HTTP server request method enumeration. More...
 
enum  M2MB_URI_AUTH_FLAG {
  M2MB_URI_FLAG_NOAUTH = 0x00,
  M2MB_URI_FLAG_AUTHBASIC = 0x02,
  M2MB_URI_FLAG_AUTHMD5 = 0x04
}
 HTTP server URI user authentication enumeration. More...
 
enum  M2MB_HTTPD_URI_USER_EVENT {
  M2MB_HTTPD_URI_USER_EVENT_CON_OPENED = 0x00000001,
  M2MB_HTTPD_URI_USER_EVENT_CON_CLOSE = 0x00000010,
  M2MB_HTTPD_URI_USER_EVENT_HEADERS_RECV = 0x00000100,
  M2MB_HTTPD_URI_USER_EVENT_FORM_RECV = 0x00001000,
  M2MB_HTTPD_URI_USER_EVENT_BODY_RECV = 0x00010000,
  M2MB_HTTPD_URI_USER_EVENT_ALL_RECV = 0x00100000,
  M2MB_HTTPD_URI_USER_EVENT_FORM_FILE_RECV = 0x01000000
}
 HTTP server URI user event enumeration. More...
 
typedef enum M2MB_URI_AUTH_FLAG M2MB_URI_AUTH_FLAG_T
 HTTP server URI user authentication enumeration. More...
 
typedef enum M2MB_HTTPD_URI_USER_EVENT M2MB_HTTPD_URI_USER_EVENT_E
 HTTP server URI user event enumeration. More...
 
typedef struct M2MB_HTTPD_CONFIG_S M2MB_HTTPD_CONFIG_T
 HTTP server configuration structure. More...
 
typedef struct M2MB_HTTPD_URI_CTX M2MB_HTTPD_URICTX_T
 HTTP server URI context structure. More...
 
typedef struct M2MB_HTTPD_URI_REQ_INFO M2MB_HTTPD_URI_REQ_INFO_T
 HTTP server URI Request structure. More...
 
typedef struct M2MB_HTTPD_URI_REQ_CGI_KEY_PAIR M2MB_HTTPD_URI_REQ_CGI_KEY_PAIR_T
 HTTP server CGI parameter pair structure. More...
 
typedef struct M2MB_HTTPD_URI_REQ_CGI_FORM_DATA M2MB_HTTPD_URI_REQ_CGI_FORM_DATA_T
 HTTP server CGI form data structure. More...
 
typedef INT32(* M2MB_HTTPD_URI_HANDLER_T) (VOID *conn_handle, VOID *usr_ctx, INT32 **event)
 HTTP server URI Request user call back prototype. More...
 
M2MB_STATUS_T m2mb_httpd_init (M2MB_HTTPD_CONFIG_T *cfg, M2MB_SSL_CTXT_HANDLE ssl_handle)
 HTTP server initialization. More...
 
M2MB_STATUS_T m2mb_httpd_deinit ()
 HTTP server initialization. More...
 
M2MB_STATUS_T m2mb_httpd_start ()
 Start HTTP server. More...
 
M2MB_STATUS_T m2mb_httpd_stop ()
 Stop HTTP server. More...
 
M2MB_STATUS_T m2mb_httpd_is_started ()
 Status of HTTP server. More...
 
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. More...
 
M2MB_OS_RESULT_E m2mb_httpd_uri_decfg (char *uri)
 De-Configure URI from HTTP server. More...
 
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. More...
 
M2MB_STATUS_T m2mb_httpd_send_data (VOID *conn_handle, const INT8 *data, UINT32 length)
 Send HTTP data. More...
 
M2MB_STATUS_T m2mb_httpd_get_message_body (VOID *conn_handle, INT8 *buf, UINT32 *plen)
 Get Message Body of URI request. More...
 
M2MB_STATUS_T m2mb_httpd_get_message_head (VOID *conn_handle, UINT8 *buf, UINT32 *plen)
 Get Message header of URI request. More...
 
INT32 m2mb_httpd_get_content_len (VOID *conn_handle)
 Get content length. More...
 
CHARm2mb_httpd_get_body_location (VOID *conn_handle)
 Get message body location. More...
 
INT32 m2mb_httpd_get_request_type (VOID *conn_handle)
 Get request type. More...
 
M2MB_HTTPD_URI_REQ_CGI_FORM_DATA_Tm2mb_httpd_get_cgi_form (VOID *conn_handle)
 Get CGI form data. More...
 
VOIDm2mb_httpd_FindURICtx_FromIndex (INT32 index)
 Get URI context from URI's index. More...
 
M2MB_STATUS_T m2mb_httpd_user_add (const char *username, const char *password)
 Add a USER to HTTPD module. More...
 
M2MB_STATUS_T m2mb_httpd_user_del (const char *username, const char *password)
 Delete a USER to HTTPD module. More...
 
M2MB_STATUS_T m2mb_httpd_user_validate (char *username, char *password)
 Validate a USER to HTTPD module. More...
 
M2MB_STATUS_T m2mb_httpd_user_change_password (char *username, char *cur_password, char *new_password)
 Change password of a USER to HTTPD module. More...
 

Detailed Description

This section describes the M2MB APIs to perform HTTP server operations.

Macro Definition Documentation

◆ M2MB_HTTPD_PATH_MAX

#define M2MB_HTTPD_PATH_MAX   31

Maximum length of path

Definition at line 51 of file m2mb_httpd.h.

◆ M2MB_HTTPD_SRVR_NAME_MAX

#define M2MB_HTTPD_SRVR_NAME_MAX   512

Maximum length of Server

Definition at line 52 of file m2mb_httpd.h.

Typedef Documentation

◆ 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.

◆ M2MB_HTTPD_URI_HANDLER_T

typedef INT32(* M2MB_HTTPD_URI_HANDLER_T) (VOID *conn_handle, VOID *usr_ctx, INT32 **event)

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.

◆ M2MB_HTTPD_URI_REQ_CGI_FORM_DATA_T

HTTP server CGI form data structure.

Structure containing members representing CGI form data.

◆ M2MB_HTTPD_URI_REQ_CGI_KEY_PAIR_T

HTTP server CGI parameter pair structure.

Structure containing members representing a pair of CGI parameters.

◆ M2MB_HTTPD_URI_REQ_INFO_T

HTTP server URI Request structure.

Structure containing members representing URI request received.

◆ M2MB_HTTPD_URI_USER_EVENT_E

HTTP server URI user event enumeration.

This enum defines macros for type of user events for URI operations.

◆ M2MB_HTTPD_URICTX_T

HTTP server URI context structure.

Structure for storing HTTP server URI context related to particular URI.

◆ M2MB_URI_AUTH_FLAG_T

HTTP server URI user authentication enumeration.

This enum defines macros for type of user authentication supported for URI.

Enumeration Type Documentation

◆ M2MB_HTTPD_CGI_RETURN_E

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.

◆ M2MB_HTTPD_METHOD_E

HTTP server request method enumeration.

This enum defines macros for request methods that are supported by HTTP server.

Enumerator
M2MB_HTTPD_METHOD_INVALID 

Invalid request

M2MB_HTTPD_METHOD_GET 

Get request

M2MB_HTTPD_METHOD_HEAD 

Head request

M2MB_HTTPD_METHOD_POST 

Post request

M2MB_HTTPD_METHOD_PUT 

Put request

M2MB_HTTPD_METHOD_DELETE 

Delete request

M2MB_HTTPD_METHOD_TRACE 

Trace request

M2MB_HTTPD_METHOD_POSTMULTI 

Internal webserver operation - not HTTP request type

Definition at line 87 of file m2mb_httpd.h.

◆ 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.

◆ M2MB_HTTPD_URI_USER_EVENT

HTTP server URI user event enumeration.

This enum defines macros for type of user events for URI operations.

Enumerator
M2MB_HTTPD_URI_USER_EVENT_CON_OPENED 

Connection has been accepted

M2MB_HTTPD_URI_USER_EVENT_CON_CLOSE 

Connection has been closed

M2MB_HTTPD_URI_USER_EVENT_HEADERS_RECV 

Request headers received

M2MB_HTTPD_URI_USER_EVENT_FORM_RECV 

Multipart form data received

M2MB_HTTPD_URI_USER_EVENT_BODY_RECV 

Part of request body received

M2MB_HTTPD_URI_USER_EVENT_ALL_RECV 

Entire request is received

M2MB_HTTPD_URI_USER_EVENT_FORM_FILE_RECV 

File is received in name-value pair

Definition at line 117 of file m2mb_httpd.h.

◆ 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.

Function Documentation

◆ m2mb_httpd_deinit()

M2MB_STATUS_T m2mb_httpd_deinit ( )

HTTP server initialization.

This API deinitializes HTTP server.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_deinit( );

int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
...
result = m2mb_httpd_deinit( );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_FindURICtx_FromIndex()

VOID* m2mb_httpd_FindURICtx_FromIndex ( INT32  index)

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).

Parameters
[in]indexInteger number indicating the index number.
Returns
Returns the pointer to the URI context on SUCCESS and NULL otherwise.

m2mb_httpd_FindURICtx_FromIndex( index );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs

◆ m2mb_httpd_get_body_location()

CHAR* m2mb_httpd_get_body_location ( VOID conn_handle)

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).

Parameters
[in]conn_handlePointer representing the HTTP server handle.
Returns
Returns an the pointer to body location on SUCCESS and NULL otherwise.

m2mb_httpd_get_content_len( conn_handle );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
INT32 content_len = 0;
...
content_len = m2mb_httpd_get_content_len( conn_handle );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_get_cgi_form()

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.

Parameters
[in]conn_handlePointer representing the HTTP server handle.
Returns
Returns the address of the form data if it is present, NULL otherwise.

m2mb_httpd_get_cgi_form( conn_handle );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start and in m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
INT32 req_type = 0;
VOID *form_data = NULL;
...
form_data = m2mb_httpd_get_cgi_form( conn_handle );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_get_content_len()

INT32 m2mb_httpd_get_content_len ( VOID 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).

Parameters
[in]conn_handlePointer representing the HTTP server handle.
Returns
Returns an non zero integer on SUCCESS and Zero otherwise.

m2mb_httpd_get_content_len( conn_handle );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
INT32 content_len = 0;
...
content_len = m2mb_httpd_get_content_len( conn_handle );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_get_message_body()

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.

Parameters
[in]conn_handlePointer representing the HTTP server handle.
[in]bufBuffer to where body from the response from Server to Client should be copied as the content.
[in]plenPointer to an integer mentioning the length of the content required from the response form Server to Client.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_get_message_body( conn_handle, buffer, pLength );

INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
UINT8 *buffer = NULL;
UINT32 length = 0;
...
if( M2MB_OK != m2mb_httpd_get_message_body( conn_handle, NULL, &length ))
{
return M2MB_ERROR;
}
buffer = malloc( *length );
if( M2MB_OK != m2mb_httpd_get_message_body( conn_handle, buffer, &length ))
{
return M2MB_ERROR;
}
...
m2mb_httpd_send_http_headers( conn_handle, "test/plain", 10, 200, "SUCCESS", "" );
m2mb_httpd_send_http_data( hp, "0123456789", 10 );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_get_message_head()

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.

Parameters
[in]conn_handlePointer representing the HTTP server handle.
[in]bufBuffer to where header from the response from Server to Client should be copied as the content.
[in]plenPointer to an integer mentioning the length of the header required from the response form Server to Client.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_get_message_head( hp, buffer, pLength );

INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
UINT8 *buffer = NULL;
UINT32 length = 0;
...
if( M2MB_OK != m2mb_httpd_get_message_head( conn_handle, NULL, &length ))
{
return M2MB_ERROR;
}
buffer = malloc( *length );
if( M2MB_OK != m2mb_httpd_get_message_head( conn_handle, buffer, &length ))
{
return M2MB_ERROR;
}
...
m2mb_httpd_send_http_headers( conn_handle, "test/plain", 10, 200, "SUCCESS", "" );
m2mb_httpd_send_http_data( hp, "0123456789", 10 );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_get_request_type()

INT32 m2mb_httpd_get_request_type ( VOID conn_handle)

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).

Parameters
[in]conn_handlePointer representing the HTTP server handle.
Returns
Returns the request type defined by M2MB_HTTPD_METHOD_E on SUCCESS and Zero otherwise.

m2mb_httpd_get_request_type( conn_handle );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
INT32 req_type = 0;
...
req_type = m2mb_httpd_get_request_type( conn_handle );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_init()

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.

Parameters
[in]cfgUser should pass the configuration of HTTP server by using M2MB_HTTPD_CONFIG_T structure.
[in]ssl_handleHandler to SSL created by using m2mb_ssl_init API.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_init( pCfg, ssl_handle );

int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_is_started()

M2MB_STATUS_T m2mb_httpd_is_started ( )

Status of HTTP server.

This API gives the running status of HTTP server.

Returns
Returns M2MB_OK if HTTP server is running, M2MB_ERROR if not running.

m2mb_httpd_is_started( );

int main()
{
M2MB_STATUS_T result;
result = m2mb_httpd_is_started( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_send_data()

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).

Parameters
[in]conn_handlePointer representing the HTTP server handle.
[in]dataData going in the response from Server to Client as the content.
[in]lengthAn integer mentioning the length of the content going in the response from Server to Client.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_send_http_data( hp, "0123456789", 10 );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
...
m2mb_httpd_send_http_headers( conn_handle, "test/plain", 10, 200, "SUCCESS", "" );
m2mb_httpd_send_http_data( hp, "0123456789", 10 );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_send_headers()

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).

Parameters
[in]conn_handlePointer representing the HTTP server handle.
[in]content_typeString mentioning the type of content going in the response from Server to Client.
[in]content_lengthAn integer mentioning the length of the content going in the response from Server to Client.
[in]status_codeStatus code defining the response from the server. Please refer to generic status codes the HTTP server support.
[in]status_textUser defined status string corresponding to the status code.
[in]user_headersUser defined headers in a string format. Every header should be separated by CR+LF.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_send_headers( hp, "test/plain", 100, 200, "SUCCESS", "" );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_uri_cfg APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
...
m2mb_httpd_send_headers( conn_handle, "test/plain", 100, 200, "SUCCESS", "" );
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_start()

M2MB_STATUS_T m2mb_httpd_start ( )

Start HTTP server.

This API starts HTTP server.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure
Note
This API has to be called after m2mb_httpd_init API is called.

m2mb_httpd_start( );

int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
...
result = m2mb_httpd_start( );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_stop()

M2MB_STATUS_T m2mb_httpd_stop ( )

Stop HTTP server.

This API stops HTTP server.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure
Note
This API has to be called after m2mb_httpd_init API is called.

m2mb_httpd_stop( );

int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
...
result = m2mb_httpd_start( );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
...
result = m2mb_httpd_stop( );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_uri_cfg()

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.

Parameters
[in]uriString representing URI.
[in]methodsMethods supported by the URI, it can be a combination of many ET, POST, HEAD.
[in]flagFlag mentioning the type of authentication used for the URI defined by M2MB_URI_AUTH_FLAG_T.
[in]fn_cbUser 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_ctxUser callback context to be used in handling the requests to be received on this URI.
Returns
Returns different status values defined by M2MB_OS_RESULT_E based on the result of the operation.

m2mb_httpd_uri_cfg( "test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start APIs
INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "/test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_uri_decfg()

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.

Returns
Returns different status values defined by M2MB_OS_RESULT_E based on the result of the operation.

m2mb_httpd_uri_decfg("test");

INT32 test_uri_callback( VOID* conn_handle, VOID* usr_ctx, INT32 **event )
{
...
}
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
m2mb_httpd_uri_cfg( "test", "GET,POST", M2MB_URI_FLAG_NOAUTH, test_uri_callback, NULL ))
{
return M2MB_ERROR;
}
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_user_add()

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.

Parameters
[in]usernameA NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1.
[in]passwordA NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.

m2mb_httpd_user_add( "admin", "password" );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start APIs
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
if( M2MB_OS_SUCCESS != m2mb_httpd_user_add( "admin", "password" ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_user_change_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.

Parameters
[in]usernameA NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1.
[in]cur_passwordA NULL-terminated password string representing current password. The name length cannot be over MAX_USERLENGTH - 1.
[in]new_passwordA NULL-terminated password string representing new password. The name length cannot be over MAX_USERLENGTH - 1.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.

m2mb_httpd_user_validate( "admin", "password", "new_password" );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_user_add APIs
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
if( M2MB_OS_SUCCESS != m2mb_httpd_user_add( "admin", "password" ))
{
return M2MB_ERROR;
}
...
if( M2MB_OS_SUCCESS != m2mb_httpd_user_change_password( "admin", "password", "password1" ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_user_del()

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.

Parameters
[in]usernameA NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1.
[in]passwordA NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.

m2mb_httpd_user_del( "admin", "password" );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_user_add APIs
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
if( M2MB_OS_SUCCESS != m2mb_httpd_user_add( "admin", "password" ))
{
return M2MB_ERROR;
}
...
if( M2MB_OS_SUCCESS != m2mb_httpd_user_del( "admin", "password" ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_user_validate()

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.

Parameters
[in]usernameA NULL-terminated textual name of a user. The name length cannot be over MAX_USERLENGTH - 1.
[in]passwordA NULL-terminated password string. The name length cannot be over MAX_USERLENGTH - 1.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.

m2mb_httpd_user_validate( "admin", "password" );

Note
This API is better called after m2mb_httpd_init, m2mb_httpd_start, m2mb_httpd_user_add APIs
int main()
{
M2MB_STATUS_T result;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
//Fill the configuration structure here and get the SSL handle if needed.
...
result = m2mb_httpd_init( &cfg, ssl_handle);
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
if( M2MB_OS_SUCCESS != m2mb_httpd_user_add( "admin", "password" ))
{
return M2MB_ERROR;
}
...
if( M2MB_OS_SUCCESS != m2mb_httpd_user_validate( "admin", "password" ))
{
return M2MB_ERROR;
}
return M2MB_OK;
}