5.6.0.0R1
Software Development Kit
HTTP Server

Data Structures

struct  ltrx_http_dynamic_callback
 HTTP server dynamic callback. More...
 
struct  ltrx_http_query_data
 HTTP server query data. More...
 

Enumerations

enum  ltrx_http_header_content_type { LTRX_HTTP_HEADER_CONTENT_TYPE__TEXT_PLAIN, LTRX_HTTP_HEADER_CONTENT_TYPE__MULTIPART_FORM_DATA, LTRX_HTTP_HEADER_CONTENT_TYPE__APPLICATION_X_WWW_FORM_URLENCODED, LTRX_HTTP_HEADER_CONTENT_TYPE__OTHERS }
 HTTP server header content types. More...
 
enum  ltrx_http_header_method {
  LTRX_HTTP_HEADER_METHOD__GET, LTRX_HTTP_HEADER_METHOD__POST, LTRX_HTTP_HEADER_METHOD__PUT, LTRX_HTTP_HEADER_METHOD__DELETE,
  LTRX_HTTP_HEADER_METHOD__MKCOL, LTRX_HTTP_HEADER_METHOD__OPTIONS, LTRX_HTTP_HEADER_METHOD__OTHERS
}
 HTTP server header methods. More...
 

Functions

void ltrx_http_dynamic_callback_register (const struct ltrx_http_dynamic_callback *hdc)
 Register a dynamic callback. More...
 
void ltrx_http_error (struct ltrx_http_client *client)
 Declares an error on the HTTP client. More...
 
enum ltrx_http_header_content_type ltrx_http_get_content_type (struct ltrx_http_client *client)
 Get content type. More...
 
enum ltrx_http_header_method ltrx_http_get_header_method (const struct ltrx_http_client *client)
 Get header method. More...
 
const char * ltrx_http_get_request_path (const struct ltrx_http_client *client)
 Retrieves the HTTP request path for the current HTTP client. More...
 
const char * ltrx_http_get_request_query_data (const struct ltrx_http_client *client)
 Retrieves the complete HTTP GET request query string. More...
 
bool ltrx_http_multipart_process (struct ltrx_http_client *client, struct ltrx_http_query_data *query_data[], bool(*unknownKeyHandler)(struct ltrx_http_client *client, struct ltrx_http_multipart_parse_data *pMultipart_Data, const char *key, const char *attribute_key, void *arg), void *arg, struct ltrx_write_user_message_info *lwumi)
 Process key/value parameters in HTTP POST request multipart/form-data body. More...
 
int ltrx_http_multipart_read_char (struct ltrx_http_client *client, struct ltrx_http_multipart_parse_data *pData)
 Reads a single character from a multipart stream. More...
 
int ltrx_http_read_char_from_body_stream (struct ltrx_http_client *client)
 Reads a single character from the body stream. More...
 
void ltrx_http_send_data_encoded (struct ltrx_http_client *client, const char *data)
 Encodes and sends data to the HTTP client. More...
 
void ltrx_http_send_data_flush (struct ltrx_http_client *client)
 Pushes out any pending data to the HTTP client. More...
 

Detailed Description

HTTP Server.

Enumeration Type Documentation

◆ ltrx_http_header_content_type

HTTP server header content types.

Enumerator
LTRX_HTTP_HEADER_CONTENT_TYPE__TEXT_PLAIN 

text/plain.

LTRX_HTTP_HEADER_CONTENT_TYPE__MULTIPART_FORM_DATA 

multipart/form-data.

LTRX_HTTP_HEADER_CONTENT_TYPE__APPLICATION_X_WWW_FORM_URLENCODED 

application/x-www-form-urlencoded.

LTRX_HTTP_HEADER_CONTENT_TYPE__OTHERS 

Any other.

◆ ltrx_http_header_method

HTTP server header methods.

Enumerator
LTRX_HTTP_HEADER_METHOD__GET 

GET.

LTRX_HTTP_HEADER_METHOD__POST 

POST.

LTRX_HTTP_HEADER_METHOD__PUT 

PUT.

LTRX_HTTP_HEADER_METHOD__DELETE 

DELETE.

LTRX_HTTP_HEADER_METHOD__MKCOL 

MKCOL.

LTRX_HTTP_HEADER_METHOD__OPTIONS 

OPTIONS.

LTRX_HTTP_HEADER_METHOD__OTHERS 

Any other.

Function Documentation

◆ ltrx_http_dynamic_callback_register()

void ltrx_http_dynamic_callback_register ( const struct ltrx_http_dynamic_callback hdc)

Register a dynamic callback.

The input struct contains the callback reference and the URI name under which to register.

Parameters
[in]hdcThe definition of the dynamic callback.

◆ ltrx_http_error()

void ltrx_http_error ( struct ltrx_http_client *  client)

Declares an error on the HTTP client.

Parameters
clientCurrent HTTP client context.
Usage/Comments:
This can be used to shut down a multipart input.

◆ ltrx_http_get_content_type()

enum ltrx_http_header_content_type ltrx_http_get_content_type ( struct ltrx_http_client *  client)

Get content type.

Parameters
clientCurrent HTTP client context.
Returns
Content type of the HTTP client request.

◆ ltrx_http_get_header_method()

enum ltrx_http_header_method ltrx_http_get_header_method ( const struct ltrx_http_client *  client)

Get header method.

Parameters
clientCurrent HTTP client context.
Returns
Header method of the HTTP client request.

◆ ltrx_http_get_request_path()

const char* ltrx_http_get_request_path ( const struct ltrx_http_client *  client)

Retrieves the HTTP request path for the current HTTP client.

Parameters
clientCurrent HTTP client context.
Return values
requestPathReturn HTTP client request path if succeeded.
NULLError occurred.
Usage/Comments:
An HTTP request path is the URL path after the registered URL for an ajax callback. One use case is that, instead of registering multiple callbacks for different URL (which consumes RAM), a module can register an ajax callback function to a root URL and uses request path to hierarchically decide what to do with different URL. E.g. if <module> wants to handle URL /ajax/<module>/<request1> and /ajax/<module>/<request2>, the module can register /<module> and strcmp <request1> and <request2> in its callback. See getAjaxCbk() in wm_wlan_profile.c for example. Note: This function only makes sense for a GET request. Ajax function registered to POST request always have a URL of "/".

◆ ltrx_http_get_request_query_data()

const char* ltrx_http_get_request_query_data ( const struct ltrx_http_client *  client)

Retrieves the complete HTTP GET request query string.

Parameters
clientCurrent HTTP client context.
Return values
requestQueryReturn the complete HTTP client GET request query string if succeeded.
NULLError occurred.
Usage/Comments:
An HTTP GET request query string is the string after the URL path. E.g. Query string for http://&lt;hostname&gt;/ajax/test?a=1&b=2&c=3 is "a=1&b=2&c=3" Note: For complete feature support, we should be able to create a function to get query value by key since a GET request query string is stored in RAM (vs POST request always stream read and discard data). We currently store URL path info and query string in http_client.uri and it has a buffer size of only MAX_HTTP_SERVER_URI .

◆ ltrx_http_multipart_process()

bool ltrx_http_multipart_process ( struct ltrx_http_client *  client,
struct ltrx_http_query_data query_data[],
bool(*)(struct ltrx_http_client *client, struct ltrx_http_multipart_parse_data *pMultipart_Data, const char *key, const char *attribute_key, void *arg)  unknownKeyHandler,
void *  arg,
struct ltrx_write_user_message_info lwumi 
)

Process key/value parameters in HTTP POST request multipart/form-data body.

Parameters
clientCurrent HTTP client context.
query_dataAn array of structure defining the keys and value buffers to be filled in by this function.
unknownKeyHandlerCallback function to handle key not found in query_data[] array. key is the current unknown key to be handled by unknownKeyHandler. If an attribute presents, unknownKeyHandler will be called with the current attribute key attribute_key to indicate its ready to process the attribute value. When all attributes are processed, unknownKeyHandler will be called with attribute_key == NULL to indicate its ready to process the value. unknownKeyHandler should return true to indicate the current key is processed or false otherwise.
argArgument to be passed to unknownKeyHandler.
lwumiMessage reporting structure used internally.
Return values
trueProcess succeeded
falseError (including native HTTP error) occurred

◆ ltrx_http_multipart_read_char()

int ltrx_http_multipart_read_char ( struct ltrx_http_client *  client,
struct ltrx_http_multipart_parse_data *  pData 
)

Reads a single character from a multipart stream.

Parameters
clientCurrent HTTP client context.
pDataMultipart parse data context.
Return values
characterReturns a single character if not negative.
-1Error occurred.

◆ ltrx_http_read_char_from_body_stream()

int ltrx_http_read_char_from_body_stream ( struct ltrx_http_client *  client)

Reads a single character from the body stream.

Parameters
clientCurrent HTTP client context.
Return values
characterReturns a single character if not negative.
-1Means "content_length" has been reached.
-2Means timeout, client close, or data exceeds buffer length.
-3Means NULL client pointer.

◆ ltrx_http_send_data_encoded()

void ltrx_http_send_data_encoded ( struct ltrx_http_client *  client,
const char *  data 
)

Encodes and sends data to the HTTP client.

Parameters
clientCurrent HTTP client context.
dataZero-terminated character data.
Usage/Comments:
Performs two passes, expanding special characters with HTML codes. Special characters are <, >, ", &, \, and Circle-R.

◆ ltrx_http_send_data_flush()

void ltrx_http_send_data_flush ( struct ltrx_http_client *  client)

Pushes out any pending data to the HTTP client.

Parameters
clientCurrent HTTP client context.