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

Webserver utility functions. More...

#include "compile_time.h"
#include "src/webserver/utility.h"
#include "src/lib/cache/cache_disk_images.h"
#include "src/lib/config/config_def.h"
#include "src/lib/filehandler.h"
#include "src/lib/log.h"
#include "src/lib/sds/sds_extras.h"
#include "src/lib/sds/sds_file.h"
#include "src/lib/sds/sds_url.h"
#include "src/webserver/response.h"
Include dependency graph for utility.c:

Functions

bool webserver_enforce_acl (struct mg_connection *nc, sds acl)
bool webserver_enforce_conn_limit (struct mg_connection *nc, int connection_count)
struct mg_connection * get_nc_by_id (struct mg_mgr *mgr, unsigned long id)
struct t_listwebserver_parse_arguments (struct mg_http_message *hm)
sds print_ip (sds s, struct mg_addr *addr)
sds get_uri_param (struct mg_str *query, const char *name)
bool get_partition_from_uri (struct mg_connection *nc, struct mg_http_message *hm, struct t_frontend_nc_data *frontend_nc_data)
bool check_imagescache (struct mg_connection *nc, struct mg_http_message *hm, struct t_mg_user_data *mg_user_data, const char *type, sds uri_decoded, int offset)
sds webserver_find_image_file (sds basefilename)
bool find_image_in_folder (sds *coverfile, sds music_directory, sds path, sds *names, int names_len)
void webserver_handle_connection_close (struct mg_connection *nc)

Variables

static const char * image_file_extensions []

Detailed Description

Webserver utility functions.

Function Documentation

◆ check_imagescache()

bool check_imagescache ( struct mg_connection * nc,
struct mg_http_message * hm,
struct t_mg_user_data * mg_user_data,
const char * type,
sds uri_decoded,
int offset )

Checks the covercache and serves the image

Parameters
ncmongoose connection
hmhttp message
mg_user_datapointer to mongoose configuration
typecache type: cover or thumbs
uri_decodedimage uri
offsetembedded image offset
Returns
true if an image is served, false if no image was found in cache

◆ find_image_in_folder()

bool find_image_in_folder ( sds * coverfile,
sds music_directory,
sds path,
sds * names,
int names_len )

Finds an image in a specific subdir in dir

Parameters
coverfilepointer to already allocated sds string to append the found image path
music_directoryparent directory
pathsubdirectory
namessds array of names
names_lenlength of sds array
Returns
true on success, else false

◆ get_nc_by_id()

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

Returns the mongoose connection by id

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

◆ get_partition_from_uri()

bool get_partition_from_uri ( struct mg_connection * nc,
struct mg_http_message * hm,
struct t_frontend_nc_data * frontend_nc_data )

Sets the partition from uri and handles errors

Parameters
ncmongoose connection
hmhttp message
frontend_nc_datafrontend nc data
Returns
true on success, else false

◆ get_uri_param()

sds get_uri_param ( struct mg_str * query,
const char * name )

Gets and decodes an url parameter. The key will not be url decoded before matching.

Parameters
queryquery string to parse
namename to get, you must append "=" to the name
Returns
url decoded value or NULL on error

◆ print_ip()

sds print_ip ( sds s,
struct mg_addr * addr )

Prints the ip address from a mg_addr struct

Parameters
salready allocated sds string to append the ip
addrpointer to struct mg_addr
Returns
sds pointer to s

◆ webserver_enforce_acl()

bool webserver_enforce_acl ( struct mg_connection * nc,
sds acl )

Public functions 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

◆ webserver_enforce_conn_limit()

bool webserver_enforce_conn_limit ( struct mg_connection * nc,
int connection_count )

Enforces the connection limit

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

◆ webserver_find_image_file()

sds webserver_find_image_file ( sds basefilename)

Finds the first image with basefilename by trying out extensions

Parameters
basefilenamebasefilename to append extensions
Returns
pointer to extended basefilename on success, else empty

◆ webserver_handle_connection_close()

void webserver_handle_connection_close ( struct mg_connection * nc)

Drains the connection if connection is set to close

Parameters
ncmongoose connection

◆ webserver_parse_arguments()

struct t_list * webserver_parse_arguments ( struct mg_http_message * hm)

Extract arguments from query parameters

Parameters
hmHttp message
Returns
Parsed arguments as t_list struct.

Variable Documentation

◆ image_file_extensions

const char* image_file_extensions[]
static
Initial value:
= {
"webp", "jpg", "jpeg", "png", "svg", "avif", "jxl",
"WEBP", "JPG", "JPEG", "PNG", "SVG", "AVIF", "JXL",
NULL}

Image file extensions to detect