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

Utility functions. More...

#include "dist/sds/sds.h"
#include "src/lib/config_def.h"
#include <stdbool.h>
#include <time.h>
Include dependency graph for utility.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MEASURE_INIT
 
#define MEASURE_START   (void)clock_gettime(CLOCK_MONOTONIC, &tic);
 
#define MEASURE_END   (void)clock_gettime(CLOCK_MONOTONIC, &toc);
 
#define MEASURE_PRINT(PART, X)
 

Functions

bool is_streamuri (const char *uri)
 
bool is_virtual_cuedir (sds music_directory, sds filename)
 
const char * get_extension_from_filename (const char *filename)
 
void basename_uri (sds uri)
 
void strip_file_extension (sds filename)
 
sds replace_file_extension (sds filename, const char *ext)
 
void strip_slash (sds dirname)
 
void sanitize_filename (sds filename)
 
void sanitize_filename2 (sds filename)
 
void my_msleep (int msec)
 
sds resolv_mympd_uri (sds uri, sds mpd_host, struct t_config *config, bool prefer_ssl)
 
bool get_ipv6_support (void)
 

Detailed Description

Utility functions.

Macro Definition Documentation

◆ MEASURE_END

#define MEASURE_END   (void)clock_gettime(CLOCK_MONOTONIC, &toc);

Stop measurement

◆ MEASURE_INIT

#define MEASURE_INIT
Value:
struct timespec tic;\
struct timespec toc;

Initialize time measurement

◆ MEASURE_PRINT

#define MEASURE_PRINT (   PART,
 
)
Value:
MYMPD_LOG_DEBUG(PART, "Execution time for %s: %" PRId64 " ms", X, \
(int64_t)((toc.tv_sec * 1000 + toc.tv_nsec / 1000000) - (tic.tv_sec * 1000 + tic.tv_nsec / 1000000)));

Print measurement result

◆ MEASURE_START

#define MEASURE_START   (void)clock_gettime(CLOCK_MONOTONIC, &tic);

Start measurement

Function Documentation

◆ 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
    urisds 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
filenamefilename 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

◆ is_streamuri()

bool is_streamuri ( const char *  uri)

Checks if uri is a remote uri or a local file

Parameters
uriuri to check
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_directorympd music directory
filenamefilename 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
msecmilliseconds to sleep

◆ replace_file_extension()

sds replace_file_extension ( sds  filename,
const char *  ext 
)

Replaces the file extension

Parameters
filenamesds string to replace the extension
extnew 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
uriuri to resolv
mpd_hostmpd host
configpointer to config struct
prefer_sslPrefer https over http
Returns
resolved uri

◆ sanitize_filename()

void sanitize_filename ( sds  filename)

Replaces invalid and uncommon filename characters with "_"

Parameters
filenamesds string to sanitize

◆ sanitize_filename2()

void sanitize_filename2 ( sds  filename)

Replaces invalid filename characters with "_", same chars as vcb_isfilename

Parameters
filenamesds string to sanitize

◆ strip_file_extension()

void strip_file_extension ( sds  filename)

Removes the file extension

Parameters
filenamesds string to remove the extension

◆ strip_slash()

void strip_slash ( sds  dirname)

Strips all slashes from the end

Parameters
dirnamesds string to strip