myMPD
Internal API documentation
|
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_def.h"
#include "src/lib/filehandler.h"
#include "src/lib/log.h"
#include "src/lib/mimetype.h"
#include "src/lib/sds_extras.h"
#include "src/lib/utility.h"
Functions | |
struct t_list * | webserver_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_send_error (struct mg_connection *nc, int code, const char *msg) |
void | webserver_send_header_ok (struct mg_connection *nc, size_t len, const char *headers) |
void | webserver_send_data (struct mg_connection *nc, const char *data, size_t len, const char *headers) |
void | webserver_send_raw (struct mg_connection *nc, const char *data, size_t len) |
void | webserver_serve_file (struct mg_connection *nc, struct mg_http_message *hm, const char *headers, const char *file) |
void | webserver_send_header_redirect (struct mg_connection *nc, const char *location, const char *headers) |
void | webserver_send_header_found (struct mg_connection *nc, const char *location, const char *headers) |
void | webserver_send_cors_reply (struct mg_connection *nc) |
void | webserver_handle_connection_close (struct mg_connection *nc) |
Variables | |
static const char * | image_file_extensions [] |
Webserver utility functions.
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
nc | mongoose connection |
hm | http message |
mg_user_data | pointer to mongoose configuration |
type | cache type: cover or thumbs |
uri_decoded | image uri |
offset | embedded image offset |
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
coverfile | pointer to already allocated sds string to append the found image path |
music_directory | parent directory |
path | subdirectory |
names | sds array of names |
names_len | length of sds array |
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
nc | mongoose connection |
hm | http message |
frontend_nc_data | frontend nc data |
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.
query | query string to parse |
name | name to get, you must append "=" to the name |
sds print_ip | ( | sds | s, |
struct mg_addr * | addr | ||
) |
Prints the ip address from a mg_addr struct
s | already allocated sds string to append the ip |
addr | pointer to struct mg_addr |
sds webserver_find_image_file | ( | sds | basefilename | ) |
Finds the first image with basefilename by trying out extensions
basefilename | basefilename to append extensions |
void webserver_handle_connection_close | ( | struct mg_connection * | nc | ) |
Drains the connection if connection is set to close
nc | mongoose connection |
struct t_list * webserver_parse_arguments | ( | struct mg_http_message * | hm | ) |
Public functions Extract arguments from query parameters
hm | Http message |
void webserver_send_cors_reply | ( | struct mg_connection * | nc | ) |
Replies to preflighted requests in CORS
nc | mongoose connection |
void webserver_send_data | ( | struct mg_connection * | nc, |
const char * | data, | ||
size_t | len, | ||
const char * | headers | ||
) |
Sends binary data
nc | mongoose connection |
data | data to send |
len | length of the data to send |
headers | extra headers to add |
void webserver_send_error | ( | struct mg_connection * | nc, |
int | code, | ||
const char * | msg | ||
) |
Sends a http error response
nc | mongoose connection |
code | http error code |
msg | the error message |
void webserver_send_header_found | ( | struct mg_connection * | nc, |
const char * | location, | ||
const char * | headers | ||
) |
Sends a 302 found header
nc | mongoose connection |
location | destination for the redirect |
headers | extra headers to add |
void webserver_send_header_ok | ( | struct mg_connection * | nc, |
size_t | len, | ||
const char * | headers | ||
) |
Sends a http OK reply with content-length header
nc | mongoose connection |
len | length for the content-length header |
headers | extra headers to add |
void webserver_send_header_redirect | ( | struct mg_connection * | nc, |
const char * | location, | ||
const char * | headers | ||
) |
Sends a 301 moved permanently header
nc | mongoose connection |
location | destination for the redirect |
headers | extra headers to add |
void webserver_send_raw | ( | struct mg_connection * | nc, |
const char * | data, | ||
size_t | len | ||
) |
Sends a raw reply
nc | mongoose connection |
data | data to send |
len | length of the data to send |
void webserver_serve_file | ( | struct mg_connection * | nc, |
struct mg_http_message * | hm, | ||
const char * | headers, | ||
const char * | file | ||
) |
Serves a file defined by file from path
nc | mongoose connection |
hm | mongoose http message |
headers | extra headers to add |
file | absolute filepath to serve |
|
static |
Image file extensions to detect