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. |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
TYPE
struct HandlerParams
handler parameters
MEMBERS
void* |
m_UserData |
The user data |
Handler |
m_Handler |
The callback |
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 |
Web request handler callback
web server handle
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 |