Webserver utility functions.
More...
#include "dist/mongoose/mongoose.h"
#include "dist/sds/sds.h"
#include "src/lib/list.h"
#include "src/webserver/mg_user_data.h"
#include <stdbool.h>
Go to the source code of this file.
|
| 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) |
| |
| sds | get_uri_param (struct mg_str *query, const char *name) |
| |
| sds | print_ip (sds s, struct mg_addr *addr) |
| |
| 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) |
| |
| struct t_list * | webserver_parse_arguments (struct mg_http_message *hm) |
| |
Webserver utility functions.
◆ 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
-
| 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 |
- 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
-
| 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 |
- 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
-
| mgr | mongoose mgr |
| id | connection 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
-
| nc | mongoose connection |
| hm | http message |
| frontend_nc_data | frontend 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
-
| query | query string to parse |
| name | name 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
-
| s | already allocated sds string to append the ip |
| addr | pointer 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
-
| nc | mongoose connection |
| acl | acl 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
-
| nc | mongoose connection |
| connection_count | connection 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
-
| basefilename | basefilename 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
-
◆ webserver_parse_arguments()
| struct t_list * webserver_parse_arguments |
( |
struct mg_http_message * |
hm | ) |
|
Extract arguments from query parameters
- Parameters
-
- Returns
- Parsed arguments as t_list struct.