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/cert.h"
#include "src/lib/filehandler.h"
#include "src/lib/http_client.h"
#include "src/lib/json/json_rpc.h"
#include "src/lib/log.h"
#include "src/lib/mem.h"
#include "src/lib/mg_str_utils.h"
#include "src/lib/msg_queue.h"
#include "src/lib/sds_extras.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/tagart.h"
#include <inttypes.h>
#include <libgen.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 send_ws_notify (struct mg_mgr *mgr, struct t_work_response *response)
 
static void send_ws_notify_client (struct mg_mgr *mgr, struct t_work_response *response)
 
static struct mg_connection * get_nc_by_id (struct mg_mgr *mgr, unsigned long id)
 
static void send_raw_response (struct mg_mgr *mgr, struct t_work_response *response)
 
static void send_redirect (struct mg_mgr *mgr, struct t_work_response *response)
 
static void send_api_response (struct mg_mgr *mgr, struct t_work_response *response)
 
static bool enforce_acl (struct mg_connection *nc, sds acl)
 
static bool enforce_conn_limit (struct mg_connection *nc, int connection_count)
 
static void mongoose_log (char ch, void *param)
 
bool webserver_init (struct mg_mgr *mgr, struct t_config *config, struct t_mg_user_data *mg_user_data)
 
bool webserver_read_certs (struct t_mg_user_data *mg_user_data, struct t_config *config)
 
void * webserver_free (struct mg_mgr *mgr)
 
void * webserver_loop (void *arg_mgr)
 

Detailed Description

Webserver implementation.

Function Documentation

◆ enforce_acl()

static bool enforce_acl ( struct mg_connection *  nc,
sds  acl 
)
static

Matches the acl against the client ip and sends an error response / drains the connection if acl is not matched

Parameters
ncmongoose connection
aclacl string to check
Returns
true if acl matches, else false

◆ enforce_conn_limit()

static bool enforce_conn_limit ( struct mg_connection *  nc,
int  connection_count 
)
static

Enforces the connection limit

Parameters
ncmongoose connection
connection_countconnection count
Returns
true if connection count is not exceeded, else false

◆ ev_handler()

static 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()

static 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)

◆ get_nc_by_id()

static struct mg_connection * get_nc_by_id ( struct mg_mgr *  mgr,
unsigned long  id 
)
static

Returns the mongoose connection by id

Parameters
mgrmongoose mgr
idconnection id
Returns
struct mg_connection* or NULL if not found

◆ mongoose_log()

static void mongoose_log ( char  ch,
void *  param 
)
static

Mongoose logging function

Parameters
chcharacter to log
param

◆ parse_internal_message()

static 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()

static void read_queue ( struct mg_mgr *  mgr)
static

Private definitions

Private functions Reads and processes all messages from the queue

Parameters
mgrpointer to mongoose mgr

◆ send_api_response()

static void send_api_response ( struct mg_mgr *  mgr,
struct t_work_response response 
)
static

Sends an api response

Parameters
mgrmongoose mgr
responsejsonrpc response

◆ send_raw_response()

static void send_raw_response ( struct mg_mgr *  mgr,
struct t_work_response response 
)
static

Sends a raw http response message

Parameters
mgrmongoose mgr
responsejsonrpc response

◆ send_redirect()

static void send_redirect ( struct mg_mgr *  mgr,
struct t_work_response response 
)
static

Sends a redirect http response message

Parameters
mgrmongoose mgr
responsejsonrpc response

◆ send_ws_notify()

static void send_ws_notify ( struct mg_mgr *  mgr,
struct t_work_response response 
)
static

Broadcasts a message through all websocket connections for a specific or all partitions

Parameters
mgrmongoose mgr
responsejsonrpc notification

◆ send_ws_notify_client()

static void send_ws_notify_client ( struct mg_mgr *  mgr,
struct t_work_response response 
)
static

Sends a message through the websocket to a specific client We use the jsonprc id to identify the websocket connection

Parameters
mgrmongoose mgr
responsejsonrpc notification

◆ webserver_free()

void * webserver_free ( struct mg_mgr *  mgr)

Frees the mongoose mgr

Parameters
mgrmongoose mgr to free
Returns
NULL

◆ webserver_init()

bool webserver_init ( struct mg_mgr *  mgr,
struct t_config config,
struct t_mg_user_data mg_user_data 
)

Public functions Initializes the webserver

Parameters
mgrmongoose mgr
configpointer to myMPD config
mg_user_dataalready allocated t_mg_user_data to populate
Returns
true on success, else false

◆ webserver_loop()

void * webserver_loop ( void *  arg_mgr)

Main function for the webserver thread

Parameters
arg_mgrvoid pointer to mongoose mgr
Returns
NULL

◆ webserver_read_certs()

bool webserver_read_certs ( struct t_mg_user_data mg_user_data,
struct t_config config 
)

Reads the ssl key and certificate from disc

Parameters
mg_user_datapointer to mongoose user data
configpointer to myMPD config
Returns
true on success, else false