myMPD
Internal API documentation
Loading...
Searching...
No Matches
webserver.c File Reference

Webserver implementation. More...

#include "compile_time.h"
#include "src/webserver/webserver.h"
#include "src/lib/api.h"
#include "src/lib/http_client/http_client.h"
#include "src/lib/json/json_rpc.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/msg_queue.h"
#include "src/lib/sds/sds_extras.h"
#include "src/lib/signal.h"
#include "src/lib/thread.h"
#include "src/webserver/albumart.h"
#include "src/webserver/folderart.h"
#include "src/webserver/placeholder.h"
#include "src/webserver/playlistart.h"
#include "src/webserver/proxy.h"
#include "src/webserver/request_handler.h"
#include "src/webserver/response.h"
#include "src/webserver/tagart.h"
#include "src/webserver/websocket.h"
#include <inttypes.h>
Include dependency graph for webserver.c:

Functions

static void read_queue (struct mg_mgr *mgr)
static bool parse_internal_message (struct t_work_response *response, struct t_mg_user_data *mg_user_data)
static void ev_handler (struct mg_connection *nc, int ev, void *ev_data)
static void ev_handler_redirect (struct mg_connection *nc_http, int ev, void *ev_data)
static void mongoose_log (char ch, void *param)
struct mg_mgr * webserver_init_mgr (struct t_config *config, struct t_mg_user_data *mg_user_data)
void webserver_free (struct mg_mgr *mgr)
void * webserver_loop (void *arg_mgr)
static void handle_wakeup (struct mg_connection *nc, struct mg_str *data)
static bool check_request (struct mg_connection *nc, struct mg_http_message *hm)

Detailed Description

Webserver implementation.

Function Documentation

◆ check_request()

bool check_request ( struct mg_connection * nc,
struct mg_http_message * hm )
static

Validates the request

Parameters
ncMongoose conncection
hmHTTP Request
Returns
true on valid request, else false

◆ ev_handler()

void ev_handler ( struct mg_connection * nc,
int ev,
void * ev_data )
static

Central webserver event handler nc->label usage 0 - connection type: F = frontend connection, B = backend connection 1 - http method: G = GET, H = HEAD, P = POST 2 - connection header: C = close, K = keepalive

Parameters
ncmongoose connection
evconnection event
ev_dataevent data (http / websocket message)

◆ ev_handler_redirect()

void ev_handler_redirect ( struct mg_connection * nc,
int ev,
void * ev_data )
static

Redirects the client to https if ssl is enabled. Only requests to /browse/webradios are not redirected.

Parameters
ncmongoose connection
evconnection event
ev_dataevent data (http / websocket message)

◆ handle_wakeup()

void handle_wakeup ( struct mg_connection * nc,
struct mg_str * data )
static

Handles the data from the MG_EV_WAKEUP event

Parameters
ncMongoose connection
dataReceived data

◆ mongoose_log()

void mongoose_log ( char ch,
void * param )
static

Mongoose logging function

Parameters
chcharacter to log
param

◆ parse_internal_message()

bool parse_internal_message ( struct t_work_response * response,
struct t_mg_user_data * mg_user_data )
static

Sets the mg_user_data values from set_mg_user_data_request. Message is sent from the mympd_api thread.

Parameters
responseResponse with the data to set
mg_user_datat_mg_user_data to configure
Returns
true on success, else false

◆ read_queue()

void read_queue ( struct mg_mgr * mgr)
static

Private definitions

Private functions Reads and processes all messages from the webserver queue. This function does not block and returns immediately if the queue is empty.

Parameters
mgrpointer to mongoose mgr

◆ webserver_free()

void webserver_free ( struct mg_mgr * mgr)

Frees the mongoose mgr

Parameters
mgrmongoose mgr to free

◆ webserver_init_mgr()

struct mg_mgr * webserver_init_mgr ( struct t_config * config,
struct t_mg_user_data * mg_user_data )

Public functions Initializes the webserver

Parameters
configpointer to myMPD config
mg_user_dataalready allocated t_mg_user_data to populate
Returns
struct mg_mgr* or NULL on error

◆ webserver_loop()

void * webserver_loop ( void * arg_mgr)

Main function for the webserver thread

Parameters
arg_mgrvoid pointer to mongoose mgr
Returns
NULL