Web server functions

Simple high-level single-threaded Web server based on dmHttpServer The web-server has a handler concept similar to servlets in Java

Namespace: dmWebServer
Include: #include <dmsdk/dlib/webserver.h>
TYPES
Handler Web request handler callback
HServer web server handle
ENUMS
Result result codes
STRUCTS
struct HandlerParams handler parameters
struct Request web server request
FUNCTIONS
Result AddHandler(HServer server, const char* prefix, HandlerParams handler_params) Add a new handler
const char* GetHeader(Request* request, const char* name) Get http header value for key
Result Receive(Request* request, void* buffer, uint32_t buffer_size, uint32_t* received_bytes) Receive data
Result RemoveHandler(HServer server, const char* prefix) Remove handle
Result Send(Request request, void* data, uint32_t data_length) Send response data
Result SendAttribute(Request* request, const char* key, const char* value) Sends a header attribute
Result SetStatusCode(Request* request, int status_code) Set response status code.

Functions

AddHandler

Result AddHandler(HServer server, const char* prefix, HandlerParams handler_params)

Add a new handler

PARAMETERS

HServer server Server handle
const char* prefix Location prefix for which locations this handler should handle
HandlerParams handler_params Handler parameters

RETURNS

Result RESULT_OK on success

GetHeader

const char* GetHeader(Request* request, const char* name)

Get http header value for key

PARAMETERS

Request* request Request
const char* name Header key

RETURNS

const char* Header value. NULL if the key doesn't exists

Receive

Result Receive(Request* request, void* buffer, uint32_t buffer_size, uint32_t* received_bytes)

Receive data

PARAMETERS

Request* request Request
void* buffer Data buffer to receive to
uint32_t buffer_size Buffer size
uint32_t* received_bytes Number of bytes received

RETURNS

Result RESULT_OK on success

RemoveHandler

Result RemoveHandler(HServer server, const char* prefix)

Remove handle

PARAMETERS

HServer server Server handle
const char* prefix Prefix for handle to remove

RETURNS

Result RESULT_OK on success

Send

Result Send(Request request, void* data, uint32_t data_length)

Send response data

PARAMETERS

Request request Request handle
void* data Data to send
uint32_t data_length Data-lenght to send

RETURNS

Result RESULT_OK on success

SendAttribute

Result SendAttribute(Request* request, const char* key, const char* value)

Sends a header attribute

PARAMETERS

Request* request Request
const char* key the header name
const char* value the header value

RETURNS

Result RESULT_OK on success

SetStatusCode

Result SetStatusCode(Request* request, int status_code)

Set response status code.

PARAMETERS

Request* request Request
int status_code Status code to set

RETURNS

Result RESULT_OK on success

Structs

HandlerParams

TYPE

struct HandlerParams

handler parameters

MEMBERS

void* m_UserData The user data
Handler m_Handler The callback


Request

TYPE

struct Request

web server request

MEMBERS

const char* m_Method Request method
const char* m_Method Request resource
const char* m_Method Content-Length header
const char* m_Method Internal data


Types

Handler

Web request handler callback


HServer

web server handle


Enums

Result

result codes

RESULT_OK
RESULT_SOCKET_ERROR
RESULT_INVALID_REQUEST
RESULT_ERROR_INVAL
RESULT_HANDLER_ALREADY_REGISTRED
RESULT_HANDLER_NOT_REGISTRED
RESULT_INTERNAL_ERROR
RESULT_UNKNOWN