Utility functions.
More...
#include "compile_time.h"
#include "src/lib/utility.h"
#include "src/lib/log.h"
#include "src/lib/sds_extras.h"
#include <errno.h>
#include <ifaddrs.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
◆ basename_uri()
| void basename_uri |
( |
sds |
uri | ) |
|
Calculates the basename for files and uris
- for files the path is removed
- for uris the query string and hash is removed
- Parameters
-
| uri | sds string to modify in place |
◆ get_extension_from_filename()
| const char * get_extension_from_filename |
( |
const char * |
filename | ) |
|
Gets the extension of a filename
- Parameters
-
| filename | filename to get extension from |
- Returns
- pointer to the extension
◆ get_ipv6_support()
| bool get_ipv6_support |
( |
void |
| ) |
|
Checks for IPv6 support by searching for an IPv6 address on all interfaces
- Returns
- true on IPv6 support, else false
◆ get_local_ip()
| static sds get_local_ip |
( |
void |
| ) |
|
|
static |
Gets the ip address of the first interface
- Returns
- ip address as sds string
◆ get_mympd_host()
| static sds get_mympd_host |
( |
sds |
mpd_host, |
|
|
sds |
http_host |
|
) |
| |
|
static |
Private definitions
Private functions Gets the listening address of the embedded webserver
- Parameters
-
| mpd_host | mpd_host config setting |
| http_host | http_host config setting |
- Returns
- address of the embedded webserver as sds string
◆ is_streamuri()
| bool is_streamuri |
( |
const char * |
uri | ) |
|
Checks if uri is a remote uri or a local file
- Parameters
-
- Returns
- true it is a uri else false
◆ is_virtual_cuedir()
| bool is_virtual_cuedir |
( |
sds |
music_directory, |
|
|
sds |
filename |
|
) |
| |
Checks if the filename is a mpd virtual cue sheet directory MPD uses the cue filename as path, we simply check if the filename is a file or not
- Parameters
-
| music_directory | mpd music directory |
| filename | filename to check |
- Returns
- true if it is a cue file else false
◆ my_msleep()
| void my_msleep |
( |
int |
msec | ) |
|
Public functions Sleep function that is interuptable
- Parameters
-
| msec | milliseconds to sleep |
◆ replace_file_extension()
| sds replace_file_extension |
( |
sds |
filename, |
|
|
const char * |
ext |
|
) |
| |
Replaces the file extension
- Parameters
-
| filename | sds string to replace the extension |
| ext | new file extension |
- Returns
- newly allocated sds string with new file extension
◆ resolv_mympd_uri()
| sds resolv_mympd_uri |
( |
sds |
uri, |
|
|
sds |
mpd_host, |
|
|
struct t_config * |
config, |
|
|
bool |
prefer_ssl |
|
) |
| |
Resolves mympd:// uris to the real myMPD host address and respects the mympd_uri config option
- Parameters
-
| uri | uri to resolv |
| mpd_host | mpd host |
| config | pointer to config struct |
| prefer_ssl | Prefer https over http |
- Returns
- resolved uri
◆ sanitize_filename()
| void sanitize_filename |
( |
sds |
filename | ) |
|
Replaces invalid and uncommon filename characters with "_"
- Parameters
-
| filename | sds string to sanitize |
◆ sanitize_filename2()
| void sanitize_filename2 |
( |
sds |
filename | ) |
|
Replaces invalid filename characters with "_", same chars as vcb_isfilename
- Parameters
-
| filename | sds string to sanitize |
◆ strip_file_extension()
| void strip_file_extension |
( |
sds |
filename | ) |
|
Removes the file extension
- Parameters
-
| filename | sds string to remove the extension |
◆ strip_slash()
| void strip_slash |
( |
sds |
dirname | ) |
|
Strips all slashes from the end
- Parameters
-
| dirname | sds string to strip |
◆ invalid_filename_chars
| const char* invalid_filename_chars = "<>/.:?&$%!#=;\a\b\f\n\r\t\v\\|" |
|
static |
Invalid and uncommon characters for filenames.
◆ invalid_filename_chars2
| const char* invalid_filename_chars2 = "\a\b\f\n\r\t\v/\\" |
|
static |
Invalid characters for filenames.
◆ mympd_uris
Initial value:= {
{"mympd://webradio/", "/webradio?uri=" },
{"mympd://", "/"},
{NULL, NULL}
}
Struct for mapping the special mympd:// uris