|
Procster
0.1
Procster-ViewProcessesovertheweb
|
Small Framework to make MHD based server side develpment more bearable. More...
#include <microhttpd.h>#include <jansson.h>#include "proclister.h"#include <fcntl.h>#include <sys/stat.h>
Functions | |
| int | ms_answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) |
| Miniserver framework main request dispatcher. More... | |
| static int | ms_on_client_connect (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
| MHD Client authorization handler (Hooked as 3rd param to MHD_start_daemon()). More... | |
| void | ms_req_term_cb (void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe) |
| MHD Post request handler. More... | |
| miniserver * | server_new (json_t *json) |
| App: Instantiate server with basic settings (e.g. More... | |
| void | server_run (miniserver *s) |
| App: Start Running Server and accepting requests. More... | |
| void | server_actions_load (miniserver *s, action *actarr, int cnt) |
| App: Load actions from C Array of actions. More... | |
| request * | req_new (miniserver *s, const char *url, const char *method) |
| Allocate and initialize request. More... | |
| void | req_free (request *req) |
| Free request and its members. More... | |
| response * | res_new (action *act) |
| void | res_free (response *res) |
| action * | action_find (miniserver *s, const char *url) |
| Lookup an action (during dispatching). More... | |
| void | res_set_str_cont (response *res, char *contstr) |
| Set string content as content to respond with. More... | |
| void | res_set_conttype (response *res, char *conttype) |
| struct MHD_Response * | req_trystatic (request *req, response *res) |
| Try to resolve url to a static file and return response for it. More... | |
Small Framework to make MHD based server side develpment more bearable.
MHD has following enums to hint memory management strategy in microhttpd.h
These are extracted notes from documenation (See first flag param to MHD_start_daemon(flags, ...), see also enum MHD_FLAG). For list of flags in documenation "2 Constants". What is this: MHD_USE_SELECT_INTERNALLY
Earlier modes must be combined with event loop styles: select, poll and epoll (epoll and poll may not be available on some platforms). Are these: MHD_USE_SELECT_INTERNALLY, MHD_USE_POLL, MHD_USE_EPOLL
Other web servers:
| action* action_find | ( | miniserver * | s, |
| const char * | url | ||
| ) |
Lookup an action (during dispatching).
| s | - Server |
| url | - URL by which action node should be looked up |
References miniserver::actions, and action::url.
Referenced by main(), and ms_answer_to_connection().
| int ms_answer_to_connection | ( | void * | cls, |
| struct MHD_Connection * | connection, | ||
| const char * | url, | ||
| const char * | method, | ||
| const char * | version, | ||
| const char * | upload_data, | ||
| size_t * | upload_data_size, | ||
| void ** | con_cls | ||
| ) |
Miniserver framework main request dispatcher.
Derives the action to dispatch based on the URL.
References action_find(), response::code, response::conn, response::cont, response::contlen, response::conttype, miniserver::debug, action::hdlr, response::json, response::memmode, MHD_add_response_header(), MHD_create_response_from_buffer(), MHD_destroy_response(), miniserver::port, req_new(), req_trystatic(), request::res, res_new(), res_set_conttype(), and res_set_str_cont().
Referenced by server_run().
|
static |
MHD Client authorization handler (Hooked as 3rd param to MHD_start_daemon()).
Gets called twice per request ? No. But multiple requests can be batched to go through Access check first.
References MHD_YES.
Referenced by server_run().
| void ms_req_term_cb | ( | void * | cls, |
| struct MHD_Connection * | connection, | ||
| void ** | con_cls, | ||
| enum MHD_RequestTerminationCode | toe | ||
| ) |
MHD Post request handler.
References req_free(), request::res, and res_free().
Referenced by server_run().
| void req_free | ( | request * | req | ) |
Free request and its members.
References request::method, and request::url.
Referenced by ms_req_term_cb().
| request* req_new | ( | miniserver * | s, |
| const char * | url, | ||
| const char * | method | ||
| ) |
Allocate and initialize request.
References request::method, request::ms, and request::url.
Referenced by ms_answer_to_connection().
Try to resolve url to a static file and return response for it.
| req | - Request with URL to test for static content |
| res | - Response to set possible http return codes to (in res->code) |
References response::code, miniserver::docroot, MHD_create_response_from_fd(), request::ms, and request::url.
Referenced by ms_answer_to_connection().
| void res_free | ( | response * | res | ) |
References response::conn, and response::conttype.
Referenced by ms_req_term_cb().
References response::code, action::conttype, and response::conttype.
Referenced by ms_answer_to_connection().
| void res_set_conttype | ( | response * | res, |
| char * | conttype | ||
| ) |
References response::conttype.
Referenced by ms_answer_to_connection().
| void res_set_str_cont | ( | response * | res, |
| char * | contstr | ||
| ) |
Set string content as content to respond with.
Length is figured out from sting. Binary data not allowed with this methos.
| res | - Response (to which content is set) |
| contstr | - Content string. |
References response::cont, and response::contlen.
Referenced by ms_answer_to_connection().
| void server_actions_load | ( | miniserver * | s, |
| action * | actarr, | ||
| int | cnt | ||
| ) |
App: Load actions from C Array of actions.
| s | - Miniserver (to/for which actions will be loaded) |
| actarr | - Array of actions (not action pointers) to add |
| cnt | - Number of actions to add |
References miniserver::actions, and action::url.
Referenced by main().
| miniserver* server_new | ( | json_t * | json | ) |
App: Instantiate server with basic settings (e.g.
docroot, port).
References miniserver::debug, miniserver::docroot, docroot, miniserver::logfh, miniserver::logfname, miniserver::port, and miniserver::reqdebug.
Referenced by main().
| void server_run | ( | miniserver * | s | ) |
App: Start Running Server and accepting requests.
| s | - Server |
References ms_answer_to_connection(), ms_on_client_connect(), ms_req_term_cb(), and miniserver::port.
Referenced by main().