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

State file implementation. More...

#include "compile_time.h"
#include "src/lib/state_files.h"
#include "src/lib/convert.h"
#include "src/lib/filehandler.h"
#include "src/lib/log.h"
#include "src/lib/sds_extras.h"
#include "src/lib/utility.h"
#include "src/lib/validate.h"
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <inttypes.h>
#include <string.h>
Include dependency graph for state_files.c:

Functions

bool check_partition_state_dir (sds workdir, sds partition)
 
sds camel_to_snake (sds text)
 
sds state_file_rw_string_sds (sds workdir, const char *dir, const char *name, sds def_value, validate_callback vcb, bool write)
 
sds state_file_rw_string (sds workdir, const char *dir, const char *name, const char *def_value, validate_callback vcb, bool write)
 
bool state_file_rw_bool (sds workdir, const char *dir, const char *name, bool def_value, bool write)
 
enum mpd_tag_type state_file_rw_tag (sds workdir, const char *dir, const char *name, enum mpd_tag_type def_value, bool write)
 
int state_file_rw_int (sds workdir, const char *dir, const char *name, int def_value, int min, int max, bool write)
 
unsigned state_file_rw_uint (sds workdir, const char *dir, const char *name, unsigned def_value, unsigned min, unsigned max, bool write)
 
bool state_file_write (sds workdir, const char *subdir, const char *filename, const char *value)
 

Detailed Description

State file implementation.

Function Documentation

◆ camel_to_snake()

sds camel_to_snake ( sds  text)

Converts camel case to snake notation

Parameters
textstring to convert
Returns
newly allocated sds string in snake notation

◆ check_partition_state_dir()

bool check_partition_state_dir ( sds  workdir,
sds  partition 
)

Checks if the state dir for a partition exists

Parameters
workdirmyMPD working directory
partitionpartition name
Returns
true on success, else false

◆ state_file_rw_bool()

bool state_file_rw_bool ( sds  workdir,
const char *  dir,
const char *  name,
bool  def_value,
bool  write 
)

Reads a bool from a file or writes the file with a default value if not exists or value is invalid

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value
writeif true create the file if not exists
Returns
newly allocated sds string

◆ state_file_rw_int()

int state_file_rw_int ( sds  workdir,
const char *  dir,
const char *  name,
int  def_value,
int  min,
int  max,
bool  write 
)

Reads an int value from a file or writes the file with a default value if not exists or value is invalid

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value as sds string (is freed by this function)
minminimum value
maxmaximum value
writeif true create the file if not exists
Returns
newly allocated sds string

◆ state_file_rw_string()

sds state_file_rw_string ( sds  workdir,
const char *  dir,
const char *  name,
const char *  def_value,
validate_callback  vcb,
bool  write 
)

Reads a string from a file or writes the file with a default value if not exists or value is invalid

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value as c string
vcbvalidation callback from validate.h
writeif true create the file if not exists
Returns
newly allocated sds string

◆ state_file_rw_string_sds()

sds state_file_rw_string_sds ( sds  workdir,
const char *  dir,
const char *  name,
sds  def_value,
validate_callback  vcb,
bool  write 
)

Reads a string from a file or writes the file with a default value if not exists or value is invalid Frees the default value.

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value as sds string (is freed by this function)
vcbvalidation callback from validate.h
writeif true create the file if not exists
Returns
newly allocated sds string

◆ state_file_rw_tag()

enum mpd_tag_type state_file_rw_tag ( sds  workdir,
const char *  dir,
const char *  name,
enum mpd_tag_type  def_value,
bool  write 
)

Reads a tag name from a file, parses it to a mpd_tag_type or writes the file with a default value if not exists or value is invalid

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value as mpd_tag_type
writeif true create the file if not exists
Returns
parsed string as mpd_tag_type

◆ state_file_rw_uint()

unsigned state_file_rw_uint ( sds  workdir,
const char *  dir,
const char *  name,
unsigned  def_value,
unsigned  min,
unsigned  max,
bool  write 
)

Reads an unsigned value from a file or writes the file with a default value if not exists or value is invalid

Parameters
workdirmympd working directory
dirsubdir
namefilename to read/write
def_valuedefault value as sds string (is freed by this function)
minminimum value
maxmaximum value
writeif true create the file if not exists
Returns
newly allocated sds string

◆ state_file_write()

bool state_file_write ( sds  workdir,
const char *  subdir,
const char *  filename,
const char *  value 
)

Writes the statefile

Parameters
workdirmympd working directory
subdirsubdir
filenamefilename to write
valuevalue to write fo file
Returns
true on success else false