WE310F5  39.00.000
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
 
#define HTTP_OK   200
 
#define HTTP_CREATED   201
 
#define HTTP_ACCEPTED   202
 
#define HTTP_NO_CONTENT   204
 
#define HTTP_RESET_CONTENT   205
 
#define HTTP_REDIRECT_MULTI   300
 
#define HTTP_REDIRECT_PERM   301
 
#define HTTP_REDIRECT_TEMP   302
 
#define HTTP_REDIRECT_OTHER   303
 
#define HTTP_REDIRECT_NOMOD   304
 
#define HTTP_REDIRECT_PROXY   305
 
#define HTTP_ERROR_BADREQ   400
 
#define HTTP_ERROR_AUTHFAIL   401
 
#define HTTP_ERROR_PAYMENT   402
 
#define HTTP_ERROR_FORBID   403
 
#define HTTP_ERROR_NOFILE   404
 
#define HTTP_ERROR_METHOD   405
 
#define HTTP_ERROR_UNACCEPT   406
 
#define HTTP_ERROR_PROXYAUT   407
 
#define HTTP_ERROR_REQTMO   408
 
#define HTTP_ERROR_CONFLICT   409
 
#define HTTP_ERROR_RESGONE   410
 
#define HTTP_ERROR_LENGTH   411
 
#define HTTP_ERROR_PREFAIL   412
 
#define HTTP_ERROR_TOOBIG   413
 
#define HTTP_ERROR_URIBIG   414
 
#define HTTP_ERROR_BADMEDIA   415
 
#define HTTP_ERROR_SERVER   500
 
#define HTTP_ERROR_NOTIMPLEMENTED   501
 
#define HTTP_ERROR_BADGATEWAY   502
 
#define HTTP_ERROR_OVERLOAD   503
 
#define HTTP_ERROR_GATEAWYTMO   504
 
#define HTTP_ERROR_HTTPVER   505
 
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 = 0x00000002,
  M2MB_HTTPD_URI_USER_EVENT_HEADERS_RECV = 0x00000004,
  M2MB_HTTPD_URI_USER_EVENT_FORM_RECV = 0x00000008,
  M2MB_HTTPD_URI_USER_EVENT_BODY_RECV = 0x00000010,
  M2MB_HTTPD_URI_USER_EVENT_ALL_RECV = 0x00000020,
  M2MB_HTTPD_URI_USER_EVENT_FORM_FILE_RECV = 0x00000040,
  M2MB_HTTPD_URI_USER_EVENT_DATA_SENT = 0x00000080
}
 HTTP server URI user event enumeration. More...
 
enum  M2MB_HTTPD_CONF_ID {
  M2MB_HTTPD_CONF_SET_REGISTER_URI = 0,
  M2MB_HTTPD_CONF_SET_DEREGISTER_URI = 1,
  M2MB_HTTPD_CONF_SET_USER_CHANGE_PASSWORD = 2,
  M2MB_HTTPD_CONF_GET_IS_STARTED = 3,
  M2MB_HTTPD_CONF_GET_MESSAGE_BODY = 4,
  M2MB_HTTPD_CONF_GET_MESSAGE_HEAD = 5,
  M2MB_HTTPD_CONF_GET_CONTENT_LEN = 6,
  M2MB_HTTPD_CONF_GET_BODY_LOCATION = 7,
  M2MB_HTTPD_CONF_GET_REQUEST_TYPE = 8,
  M2MB_HTTPD_CONF_GET_CGI_FORM = 9
}
 HTTP server GET/SET Configuration 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...
 
typedef struct M2MB_URI_CFG_S M2MB_URI_CFG_T
 
typedef enum M2MB_HTTPD_CONF_ID M2MB_HTTPD_CONF_ID_E
 HTTP server GET/SET Configuration enumeration. More...
 
typedef struct M2MB_HTTPD_INIT_PARAMS M2MB_HTTPD_INIT_PARAMS_T
 HTTPD initialization parameters. More...
 
typedef struct M2MB_HTTPD_URI_CONFIG_PARAMS M2MB_HTTPD_URI_CONFIG_PARAMS_T
 This structure is used to set HTTPD URI configuration parameters. More...
 
typedef struct M2MB_HTTPD_GET_MSG_INFO M2MB_HTTPD_GET_MSG_INFO_T
 The structure is used to GET the HEAD/BODY information. More...
 
typedef struct M2MB_HTTPD_GET_CONTENT_LEN M2MB_HTTPD_GET_CONTENT_LEN_T
 The structure is used to GET the content length of the request. More...
 
typedef struct M2MB_HTTPD_GET_BODY_LOC M2MB_HTTPD_GET_BODY_LOC_T
 The structure is used to GET the pointer to the body locaiton on the request. More...
 
typedef struct M2MB_HTTPD_GET_REQUEST_TYPE M2MB_HTTPD_GET_REQUEST_TYPE_T
 The structure is used to GET the request type on the connection handler. More...
 
typedef struct M2MB_HTTPD_GET_REQ_URI_CGI_FORM_DATA M2MB_HTTPD_GET_REQ_URI_CGI_FORM_DATA_T
 The structure is used to GET the CGI form data with the URI request. More...
 
typedef struct M2MB_HTTPD_URICTXT_FROM_INDEX M2MB_HTTPD_URICTXT_FROM_INDEX_T
 The structure is used to GET the applicaiton context of the registered URI. More...
 
typedef struct M2MB_HTTPD_USER_INFO M2MB_HTTPD_USER_INFO_T
 The structure is used to GET/SET the user information on the HTTPD module. More...
 
M2MB_STATUS_T m2mb_httpd_init (HANDLE *handle, M2MB_HTTPD_INIT_PARAMS_T *init_params)
 HTTP server deinitialization. More...
 
M2MB_STATUS_T m2mb_httpd_deinit (HANDLE handle)
 HTTP server deinitialization. More...
 
M2MB_STATUS_T m2mb_httpd_start (HANDLE handle)
 Start HTTP server. More...
 
M2MB_STATUS_T m2mb_httpd_stop (HANDLE handle)
 Stop HTTP server. More...
 
M2MB_STATUS_T m2mb_httpd_send_headers (VOID *conn_handle, UINT8 *content_type, INT32 content_length, INT32 status_code, UINT8 *status_text, UINT8 *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_set_cfg (HANDLE handle, M2MB_HTTPD_CONF_ID_E conf_id, M2MB_HTTPD_CONF_PARAMS_T *conf_params)
 SET the HTTPD configuration parameters. More...
 
M2MB_STATUS_T m2mb_httpd_get_cfg (HANDLE handle, M2MB_HTTPD_CONF_ID_E conf_id, M2MB_HTTPD_CONF_PARAMS_T *conf_params)
 GET the HTTPD configuration parameters. More...
 
M2MB_URI_CFG_Tm2mb_httpd_get_uri_cfg_from_index (INT32 index)
 Gets the URI configuration. More...
 

Detailed Description

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

WE310F5_HTTPD.png
HTTPD

Macro Definition Documentation

◆ HTTP_ACCEPTED

#define HTTP_ACCEPTED   202

Definition at line 45 of file m2mb_httpd.h.

◆ HTTP_CREATED

#define HTTP_CREATED   201

Definition at line 44 of file m2mb_httpd.h.

◆ HTTP_ERROR_AUTHFAIL

#define HTTP_ERROR_AUTHFAIL   401

Definition at line 59 of file m2mb_httpd.h.

◆ HTTP_ERROR_BADGATEWAY

#define HTTP_ERROR_BADGATEWAY   502

Definition at line 78 of file m2mb_httpd.h.

◆ HTTP_ERROR_BADMEDIA

#define HTTP_ERROR_BADMEDIA   415

Definition at line 73 of file m2mb_httpd.h.

◆ HTTP_ERROR_BADREQ

#define HTTP_ERROR_BADREQ   400

Definition at line 58 of file m2mb_httpd.h.

◆ HTTP_ERROR_CONFLICT

#define HTTP_ERROR_CONFLICT   409

Definition at line 67 of file m2mb_httpd.h.

◆ HTTP_ERROR_FORBID

#define HTTP_ERROR_FORBID   403

Definition at line 61 of file m2mb_httpd.h.

◆ HTTP_ERROR_GATEAWYTMO

#define HTTP_ERROR_GATEAWYTMO   504

Definition at line 80 of file m2mb_httpd.h.

◆ HTTP_ERROR_HTTPVER

#define HTTP_ERROR_HTTPVER   505

Definition at line 81 of file m2mb_httpd.h.

◆ HTTP_ERROR_LENGTH

#define HTTP_ERROR_LENGTH   411

Definition at line 69 of file m2mb_httpd.h.

◆ HTTP_ERROR_METHOD

#define HTTP_ERROR_METHOD   405

Definition at line 63 of file m2mb_httpd.h.

◆ HTTP_ERROR_NOFILE

#define HTTP_ERROR_NOFILE   404

Definition at line 62 of file m2mb_httpd.h.

◆ HTTP_ERROR_NOTIMPLEMENTED

#define HTTP_ERROR_NOTIMPLEMENTED   501

Definition at line 77 of file m2mb_httpd.h.

◆ HTTP_ERROR_OVERLOAD

#define HTTP_ERROR_OVERLOAD   503

Definition at line 79 of file m2mb_httpd.h.

◆ HTTP_ERROR_PAYMENT

#define HTTP_ERROR_PAYMENT   402

Definition at line 60 of file m2mb_httpd.h.

◆ HTTP_ERROR_PREFAIL

#define HTTP_ERROR_PREFAIL   412

Definition at line 70 of file m2mb_httpd.h.

◆ HTTP_ERROR_PROXYAUT

#define HTTP_ERROR_PROXYAUT   407

Definition at line 65 of file m2mb_httpd.h.

◆ HTTP_ERROR_REQTMO

#define HTTP_ERROR_REQTMO   408

Definition at line 66 of file m2mb_httpd.h.

◆ HTTP_ERROR_RESGONE

#define HTTP_ERROR_RESGONE   410

Definition at line 68 of file m2mb_httpd.h.

◆ HTTP_ERROR_SERVER

#define HTTP_ERROR_SERVER   500

Definition at line 76 of file m2mb_httpd.h.

◆ HTTP_ERROR_TOOBIG

#define HTTP_ERROR_TOOBIG   413

Definition at line 71 of file m2mb_httpd.h.

◆ HTTP_ERROR_UNACCEPT

#define HTTP_ERROR_UNACCEPT   406

Definition at line 64 of file m2mb_httpd.h.

◆ HTTP_ERROR_URIBIG

#define HTTP_ERROR_URIBIG   414

Definition at line 72 of file m2mb_httpd.h.

◆ HTTP_NO_CONTENT

#define HTTP_NO_CONTENT   204

Definition at line 46 of file m2mb_httpd.h.

◆ HTTP_OK

#define HTTP_OK   200

Definition at line 43 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_MULTI

#define HTTP_REDIRECT_MULTI   300

Definition at line 50 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_NOMOD

#define HTTP_REDIRECT_NOMOD   304

Definition at line 54 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_OTHER

#define HTTP_REDIRECT_OTHER   303

Definition at line 53 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_PERM

#define HTTP_REDIRECT_PERM   301

Definition at line 51 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_PROXY

#define HTTP_REDIRECT_PROXY   305

Definition at line 55 of file m2mb_httpd.h.

◆ HTTP_REDIRECT_TEMP

#define HTTP_REDIRECT_TEMP   302

Definition at line 52 of file m2mb_httpd.h.

◆ HTTP_RESET_CONTENT

#define HTTP_RESET_CONTENT   205

Definition at line 47 of file m2mb_httpd.h.

◆ M2MB_HTTPD_PATH_MAX

#define M2MB_HTTPD_PATH_MAX   31

Maximum length of path

Definition at line 40 of file m2mb_httpd.h.

◆ M2MB_HTTPD_SRVR_NAME_MAX

#define M2MB_HTTPD_SRVR_NAME_MAX   512

Maximum length of Server

Definition at line 41 of file m2mb_httpd.h.

Typedef Documentation

◆ M2MB_HTTPD_CONF_ID_E

HTTP server GET/SET Configuration enumeration.

This enum defines macros for various GET/SET Configuration for HTTP server module.

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

The structure is used to GET the pointer to the body locaiton on the request.

This structure is used to GET the pointer to the body locaiton on the URI request with the connection handler.

◆ M2MB_HTTPD_GET_CONTENT_LEN_T

The structure is used to GET the content length of the request.

This structure is used to GET the content length of the URI request with the connection handler.

◆ M2MB_HTTPD_GET_MSG_INFO_T

The structure is used to GET the HEAD/BODY information.

This structure is used to GET the data with HEAD/BODY of the URI request with the connection handler.

◆ M2MB_HTTPD_GET_REQ_URI_CGI_FORM_DATA_T

The structure is used to GET the CGI form data with the URI request.

This structure is used to GET the CGI form data with the URI request on the connection handler.

◆ M2MB_HTTPD_GET_REQUEST_TYPE_T

The structure is used to GET the request type on the connection handler.

This structure is used to GET the request type on the connection handler.

◆ M2MB_HTTPD_INIT_PARAMS_T

HTTPD initialization parameters.

Contains information needed to initialize the HTTPD module.

◆ M2MB_HTTPD_URI_CONFIG_PARAMS_T

This structure is used to set HTTPD URI configuration parameters.

Contains configuration information needed for registring URI.

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

This API configures given URI to the HTTP server running.

Parameters
[in]conn_handleThe connection handler of the request.
[in]usr_ctxUser context passed while coniguring the URI.
[in]eventEvent due to which the user callback has been called, and values defined by M2MB_HTTPD_URI_USER_EVENT_E.
Returns
Returns different status values defined by M2MB_OS_RESULT_E based on the result of the operation.
Note
This API is registerd with URI m2mb_httpd_set_cfg API with M2MB_HTTPD_CONF_SET_REGISTER_URI as configuration ID, after m2mb_httpd_init, m2mb_httpd_start APIs. This API is called internally on receiving the request.
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;
}
// Configure the URI
M2MB_HTTPD_CONF_PARAMS_T conf_params = {0};
M2MB_HTTPD_URI_CONFIG_PARAMS_T uri_cfg_params = {0};
uri_cfg_params.uri = "sys/test";
uri_cfg_params.methods = NULL;
uri_cfg_params.flag = 0;
uri_cfg_params.fn_cb = test_uri_callback;
uri_cfg_params.usr_ctx = NULL;
conf_params.uri_cfg_params = &uri_cfg_params;
status = m2mb_httpd_set_cfg( httpd_handle, M2MB_HTTPD_CONF_SET_REGISTER_URI, &conf_params);
if( status != M2MB_OS_SUCCESS )
{
return M2MB_ERROR;
}
return M2MB_OK;
}

Definition at line 356 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_HTTPD_URICTXT_FROM_INDEX_T

The structure is used to GET the applicaiton context of the registered URI.

This structure is used to GET the application context of the registered URI with the help of the URI index.

◆ M2MB_HTTPD_USER_INFO_T

The structure is used to GET/SET the user information on the HTTPD module.

This structure is used to GET/SET the user information on the HTTPD module.

◆ M2MB_URI_AUTH_FLAG_T

HTTP server URI user authentication enumeration.

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

◆ M2MB_URI_CFG_T

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 90 of file m2mb_httpd.h.

◆ M2MB_HTTPD_CONF_ID

HTTP server GET/SET Configuration enumeration.

This enum defines macros for various GET/SET Configuration for HTTP server module.

Enumerator
M2MB_HTTPD_CONF_SET_REGISTER_URI 

Configutation ID used to registered URI

M2MB_HTTPD_CONF_SET_DEREGISTER_URI 

Configutation ID used to Deregistered URI

M2MB_HTTPD_CONF_SET_USER_CHANGE_PASSWORD 

Configutation ID used to change the password for the user of the http server

M2MB_HTTPD_CONF_GET_IS_STARTED 

Configutation ID used to GET the status(Enabled or disabled) of HTTP server

M2MB_HTTPD_CONF_GET_MESSAGE_BODY 

Configutation ID used to GET the message body of the URI request

M2MB_HTTPD_CONF_GET_MESSAGE_HEAD 

Configutation ID used to GET the message head of the URI request

M2MB_HTTPD_CONF_GET_CONTENT_LEN 

Configutation ID used to GET the content length of the URI request

M2MB_HTTPD_CONF_GET_BODY_LOCATION 

Configutation ID used to GET the pointer to the body location on the URI request

M2MB_HTTPD_CONF_GET_REQUEST_TYPE 

Configutation ID used to GET the request type of the request received on the URI

M2MB_HTTPD_CONF_GET_CGI_FORM 

Configutation ID used to GET the CGI parameters of the request received on the URI

Definition at line 378 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 116 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 104 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 Connection has been closed

M2MB_HTTPD_URI_USER_EVENT_CON_CLOSE 

Request headers received

M2MB_HTTPD_URI_USER_EVENT_HEADERS_RECV 

Multipart form data received

M2MB_HTTPD_URI_USER_EVENT_FORM_RECV 

Part of request body received

M2MB_HTTPD_URI_USER_EVENT_BODY_RECV 

Entire request is received

M2MB_HTTPD_URI_USER_EVENT_ALL_RECV 

File is received in name-value pair

M2MB_HTTPD_URI_USER_EVENT_FORM_FILE_RECV 

Given data is sent, if more data to be sent user can send it. To send bulk data, user can fragment the data part into multiple fragment of max ts data length and send it across one per this event

M2MB_HTTPD_URI_USER_EVENT_DATA_SENT 

Definition at line 146 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 134 of file m2mb_httpd.h.

Function Documentation

◆ m2mb_httpd_deinit()

M2MB_STATUS_T m2mb_httpd_deinit ( HANDLE  handle)

HTTP server deinitialization.

This API deinitializes HTTP server.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_httpd_init API.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_deinit( );

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

◆ m2mb_httpd_get_cfg()

M2MB_STATUS_T m2mb_httpd_get_cfg ( HANDLE  handle,
M2MB_HTTPD_CONF_ID_E  conf_id,
M2MB_HTTPD_CONF_PARAMS_T conf_params 
)

GET the HTTPD configuration parameters.

This API is called to get the configuration of the HTTP server module based on the conf IDs.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_httpd_init API.
[in]conf_idGET configuration ID form enum M2MB_HTTPD_CONF_ID_E.
[in]conf_paramsconfiguration params to be passed according to the configuration required.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called after m2mb_httpd_init API is called. Example
HANDLE httpd_handle = NULL;
INT32 m2mb_http_server_uri_cb( VOID* conn_handler, VOID* usr_ctx, INT32 **pEvent )
{
INT32 event = **pEvent;
UINT32 data_len = 0;
UINT8 *data_ptr = NULL;
M2MB_HTTPD_CONF_PARAMS_T conf_params1 = {0};
M2MB_HTTPD_GET_REQUEST_TYPE_T get_request_type = {0};
get_request_type.conn_handle = conn_handler;
conf_params1.get_request_type = &get_request_type;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_REQUEST_TYPE, &conf_params1);
INT32 method = conf_params1.get_request_type->request_type;
// Get the Header( RequestLine ) length and Body length
M2MB_HTTPD_CONF_PARAMS_T conf_params2 = {0};
M2MB_HTTPD_GET_MSG_INFO_T get_msg_info = {0};
get_msg_info.conn_handle = conn_handler;
get_msg_info.buf = NULL;
get_msg_info.plen = &data_len;
conf_params2.get_msg_info = &get_msg_info;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_MESSAGE_BODY, &conf_params2);
M2MB_HTTPD_GET_BODY_LOC_T get_body_loc = {0};
get_body_loc.conn_handle = conn_handler;
conf_params2.get_body_loc = &get_body_loc;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_BODY_LOCATION, &conf_params2);
data_ptr = (CHAR *)get_body_loc.body_loc;
...
...
}
int main()
{
INT32 status = 0;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
M2MB_HTTPD_INIT_PARAMS_T httpd_init = {0};
//Fill the configuration structure here and get the SSL handle if needed.
...
...
// Store HTTPD configuration
cfg.http_Port = 80;
cfg.https_Port = 443;
cfg.rxbufsize = 1024;
cfg.txbufsize = 1024;
cfg.family = 3;
cfg.server_Name = MALLOC( strlen( "HTTP_SERVER" ) + 1 );
if( cfg.server_Name == NULL )
{
// print "Server name memory allocation failure" );
return M2MB_ERROR;
}
strncpy( cfg.server_Name, "HTTP_SERVER", strlen( Name ));
cfg.server_Name[ strlen( "HTTP_SERVER" )] = '\0';
cfg.username = "admin";
cfg.password = "admin";
httpd_init.cfg = &cfg;
httpd_init.ssl_handle = ssl_handle;
status = m2mb_httpd_init( &httpd_handle, &httpd_init );
if (status != M2MB_OK)
{
return M2MB_ERROR;
}
...
status = m2mb_httpd_start( httpd_handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
// Configure the URI
M2MB_HTTPD_CONF_PARAMS_T conf_params = {0};
M2MB_HTTPD_URI_CONFIG_PARAMS_T uri_cfg_params = {0};
uri_cfg_params.uri = "sys/test";
uri_cfg_params.methods = NULL;
uri_cfg_params.flag = 0;
uri_cfg_params.fn_cb = m2mb_http_server_uri_cb;
uri_cfg_params.usr_ctx = NULL;
conf_params.uri_cfg_params = &uri_cfg_params;
status = m2mb_httpd_set_cfg( httpd_handle, M2MB_HTTPD_CONF_SET_REGISTER_URI, &conf_params);
if( status != M2MB_OS_SUCCESS )
{
return M2MB_ERROR;
}
}

◆ m2mb_httpd_get_uri_cfg_from_index()

M2MB_URI_CFG_T* m2mb_httpd_get_uri_cfg_from_index ( INT32  index)

Gets the URI configuration.

This API gets the URI configuration of the URI registered with the server at givem URI ID. This API would be used in the callback registered during URI configuration to server (M2MB_HTTPD_URI_HANDLER_T).

Parameters
[in]indexIndex of the requested URI.
Returns
Returns an the pointer to URI configuration on SUCCESS and NULL otherwise.

m2mb_httpd_get_uri_cfg_from_index( index );

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 uriIndex = 0; //Get the uri Index from the connection 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 ( HANDLE handle,
M2MB_HTTPD_INIT_PARAMS_T init_params 
)

HTTP server deinitialization.

This API configures and initializes HTTP server. It takes the configuration of the server and SSL handle created using m2mb_ssl_open API as the input.

Parameters
[in]handleSpecifies the pointer to the context handle that can be used by other HTTP server APIs.
[in]init_paramsPointer to initialization parameters required for HTTP server module initialization.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure

m2mb_httpd_init( &handle, &init_params );

int main()
{
INT32 status = 0;
HANDLE handle = NULL;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
M2MB_HTTPD_INIT_PARAMS_T httpd_init = {0};
//Fill the configuration structure here and get the SSL handle if needed.
...
...
httpd_init.cfg = &cfg;
httpd_init.ssl_handle = ssl_handle;
status = m2mb_httpd_init( &handle, &httpd_init );
if (status != 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_HTTPD_INIT_PARAMS_T httpd_init = {0};
//Fill the configuration structure here and get the SSL handle if needed.
...
...
httpd_init.cfg = &cfg;
httpd_init.ssl_handle = ssl_handle;
result = m2mb_httpd_init( &handle, &httpd_init );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
// Configure the URI
M2MB_HTTPD_CONF_PARAMS_T conf_params = {0};
M2MB_HTTPD_URI_CONFIG_PARAMS_T uri_cfg_params = {0};
uri_cfg_params.uri = "sys/test";
uri_cfg_params.methods = NULL;
uri_cfg_params.flag = 0;
uri_cfg_params.fn_cb = test_uri_callback;
uri_cfg_params.usr_ctx = NULL;
conf_params.uri_cfg_params = &uri_cfg_params;
status = m2mb_httpd_set_cfg( httpd_handle, M2MB_HTTPD_CONF_SET_REGISTER_URI, &conf_params);
if( status != M2MB_OS_SUCCESS )
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_send_headers()

M2MB_STATUS_T m2mb_httpd_send_headers ( VOID conn_handle,
UINT8 content_type,
INT32  content_length,
INT32  status_code,
UINT8 status_text,
UINT8 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;
M2MB_HTTPD_INIT_PARAMS_T httpd_init = {0};
//Fill the configuration structure here and get the SSL handle if needed.
...
...
httpd_init.cfg = &cfg;
httpd_init.ssl_handle = ssl_handle;
result = m2mb_httpd_init( &handle, &httpd_init );
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
result = m2mb_httpd_start();
if (result != M2MB_OK)
{
return M2MB_ERROR;
}
// Configure the URI
M2MB_HTTPD_CONF_PARAMS_T conf_params = {0};
M2MB_HTTPD_URI_CONFIG_PARAMS_T uri_cfg_params = {0};
uri_cfg_params.uri = "sys/test";
uri_cfg_params.methods = NULL;
uri_cfg_params.flag = 0;
uri_cfg_params.fn_cb = test_uri_callback;
uri_cfg_params.usr_ctx = NULL;
conf_params.uri_cfg_params = &uri_cfg_params;
status = m2mb_httpd_set_cfg( httpd_handle, M2MB_HTTPD_CONF_SET_REGISTER_URI, &conf_params);
if( status != M2MB_OS_SUCCESS )
{
return M2MB_ERROR;
}
return M2MB_OK;
}

◆ m2mb_httpd_set_cfg()

M2MB_STATUS_T m2mb_httpd_set_cfg ( HANDLE  handle,
M2MB_HTTPD_CONF_ID_E  conf_id,
M2MB_HTTPD_CONF_PARAMS_T conf_params 
)

SET the HTTPD configuration parameters.

This API is called to configure the HTTP server module based on the conf IDs.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_httpd_init API.
[in]conf_idSET configuration ID form enum M2MB_HTTPD_CONF_ID_E.
[in]conf_paramsconfiguration params to be passed according to the configuration to be done.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called after m2mb_httpd_init, m2mb_httpd_start APIs needs to be called. Example
HANDLE httpd_handle = NULL;
INT32 m2mb_http_server_uri_cb( VOID* conn_handler, VOID* usr_ctx, INT32 **pEvent )
{
INT32 event = **pEvent;
UINT32 data_len = 0;
UINT8 *data_ptr = NULL;
M2MB_HTTPD_CONF_PARAMS_T conf_params1 = {0};
M2MB_HTTPD_GET_REQUEST_TYPE_T get_request_type = {0};
get_request_type.conn_handle = conn_handler;
conf_params1.get_request_type = &get_request_type;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_REQUEST_TYPE, &conf_params1);
INT32 method = conf_params1.get_request_type->request_type;
// Get the Header( RequestLine ) length and Body length
M2MB_HTTPD_CONF_PARAMS_T conf_params2 = {0};
M2MB_HTTPD_GET_MSG_INFO_T get_msg_info = {0};
get_msg_info.conn_handle = conn_handler;
get_msg_info.buf = NULL;
get_msg_info.plen = &data_len;
conf_params2.get_msg_info = &get_msg_info;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_MESSAGE_BODY, &conf_params2);
M2MB_HTTPD_GET_BODY_LOC_T get_body_loc = {0};
get_body_loc.conn_handle = conn_handler;
conf_params2.get_body_loc = &get_body_loc;
m2mb_httpd_get_cfg( httpd_handle, M2MB_HTTPD_CONF_GET_BODY_LOCATION, &conf_params2);
data_ptr = (CHAR *)get_body_loc.body_loc;
...
...
}
int main()
{
INT32 status = 0;
M2MB_HTTPD_CONFIG_T cfg = { 0 };
M2MB_SSL_CTXT_HANDLE ssl_handle = NULL;
M2MB_HTTPD_INIT_PARAMS_T httpd_init = {0};
//Fill the configuration structure here and get the SSL handle if needed.
...
...
// Store HTTPD configuration
cfg.http_Port = 80;
cfg.https_Port = 443;
cfg.rxbufsize = 1024;
cfg.txbufsize = 1024;
cfg.family = 3;
cfg.server_Name = MALLOC( strlen( "HTTP_SERVER" ) + 1 );
if( cfg.server_Name == NULL )
{
// print "Server name memory allocation failure" );
return M2MB_ERROR;
}
strncpy( cfg.server_Name, "HTTP_SERVER", strlen( Name ));
cfg.server_Name[ strlen( "HTTP_SERVER" )] = '\0';
cfg.username = "admin";
cfg.password = "admin";
httpd_init.cfg = &cfg;
httpd_init.ssl_handle = ssl_handle;
status = m2mb_httpd_init( &httpd_handle, &httpd_init );
if (status != M2MB_OK)
{
return M2MB_ERROR;
}
...
status = m2mb_httpd_start( httpd_handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
// Configure the URI
M2MB_HTTPD_CONF_PARAMS_T conf_params = {0};
M2MB_HTTPD_URI_CONFIG_PARAMS_T uri_cfg_params = {0};
uri_cfg_params.uri = "sys/test";
uri_cfg_params.methods = NULL;
uri_cfg_params.flag = 0;
uri_cfg_params.fn_cb = m2mb_http_server_uri_cb;
uri_cfg_params.usr_ctx = NULL;
conf_params.uri_cfg_params = &uri_cfg_params;
status = m2mb_httpd_set_cfg( httpd_handle, M2MB_HTTPD_CONF_SET_REGISTER_URI, &conf_params);
if( status != M2MB_OS_SUCCESS )
{
return M2MB_ERROR;
}
}

◆ m2mb_httpd_start()

M2MB_STATUS_T m2mb_httpd_start ( HANDLE  handle)

Start HTTP server.

This API starts HTTP server.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_httpd_init API.
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(handle);

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

◆ m2mb_httpd_stop()

M2MB_STATUS_T m2mb_httpd_stop ( HANDLE  handle)

Stop HTTP server.

This API stops HTTP server.

Parameters
[in]handleSpecifies the pointer to the context handle initialized by m2mb_httpd_init API.
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( handle );

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