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

String validation functions. More...

#include "src/lib/validate.h"
#include "src/lib/log.h"
#include "src/lib/mpdclient.h"
#include "src/lib/search/search.h"
#include "src/lib/sticker.h"
#include "src/lib/utf8_wrapper.h"
#include "src/lib/webradio.h"
#include "src/mympd_client/playlists.h"
#include <ctype.h>
#include <limits.h>
#include <string.h>
Include dependency graph for validate.c:

Functions

static bool check_for_invalid_chars (sds data, const char *invalid_chars)
static bool validate_json (sds data, char start, char end)
static bool is_mympd_field (sds token)
bool validate_json_object (sds data)
bool validate_json_array (sds data)
bool vcb_isalnum (sds data)
bool vcb_isdigit (sds data)
bool vcb_isprint (sds data)
bool vcb_ishexcolor (sds data)
bool vcb_isname (sds data)
bool vcb_isstickername (sds data)
bool vcb_istext (sds data)
bool vcb_isuri (sds data)
bool vcb_isstreamuri (sds data)
bool vcb_isfilename_silent (sds data)
bool vcb_isfilename (sds data)
bool vcb_isfilepath (sds data)
bool vcb_ispathfilename (sds data)
bool vcb_isfield (sds data)
bool vcb_istaglist (sds data)
bool vcb_ismpdtag (sds data)
bool vcb_ismpdtag_or_any (sds data)
bool vcb_ismpdstickertype (sds data)
bool vcb_ismpdsort (sds data)
bool vcb_isplaylistsort (sds data)
bool vcb_iswebradiosort (sds data)
bool vcb_isstickersort (sds data)
bool vcb_ismpd_sticker_sort (sds data)
bool vcb_isstickerop (sds data)
bool vcb_issearchexpression_song (sds data)
bool vcb_issearchexpression_webradio (sds data)
bool vcb_issearchexpression_mympd (sds data)
bool check_dir_traversal (const char *str)
bool path_in_folder (const char *parent, const char *child)

Variables

static const char * invalid_json_chars = "\a\b\f\v"
static const char * invalid_name_chars = "\a\b\f\n\r\t\v"
static const char * invalid_filename_chars = "\a\b\f\n\r\t\v/\\"
static const char * invalid_filepath_chars = "\a\b\f\n\r\t\v"
static const char * mympd_fields []

Detailed Description

String validation functions.

Function Documentation

◆ check_dir_traversal()

bool check_dir_traversal ( const char * str)

Checks for dir traversal attempts in string

Parameters
strstring to check
Returns
true if filepath is sane, else false

◆ check_for_invalid_chars()

bool check_for_invalid_chars ( sds data,
const char * invalid_chars )
static

Private functions Helper function to check for invalid chars in a string

Parameters
datasds string to check
invalid_charsinvalid characters
Returns
true on success else false

◆ is_mympd_field()

bool is_mympd_field ( sds token)
static

Helper function that checks if token is a valid field name

Parameters
tokenstring to check
Returns
true on success else false

◆ path_in_folder()

bool path_in_folder ( const char * parent,
const char * child )

Checks if a child path is within a parent folder

Parameters
parentparent folder path
childchild path to check
Returns
true if child is within parent, else false

◆ validate_json()

bool validate_json ( sds data,
char start,
char end )
static

Helper function that checks string for json validity

Parameters
datasds string to check
startchar the string must start with
endchar the string must end with
Returns
true on success else false

◆ validate_json_array()

bool validate_json_array ( sds data)

Checks if string is a json array

Parameters
datasds string to check
Returns
true on success else false

◆ validate_json_object()

bool validate_json_object ( sds data)

Public functions Checks if string is a json object

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isalnum()

bool vcb_isalnum ( sds data)

Checks if string is alphanumeric, including chars "_-"

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isdigit()

bool vcb_isdigit ( sds data)

Checks if string is a number

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isfield()

bool vcb_isfield ( sds data)

Checks if string is a valid column name

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isfilename()

bool vcb_isfilename ( sds data)

Checks if string is a valid filename

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isfilename_silent()

bool vcb_isfilename_silent ( sds data)

Checks if string is a valid filename Does not emit a warning

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isfilepath()

bool vcb_isfilepath ( sds data)

Checks if string is a valid filename with path or path only

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_ishexcolor()

bool vcb_ishexcolor ( sds data)

Checks if string is a hexcolor starting with #

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_ismpd_sticker_sort()

bool vcb_ismpd_sticker_sort ( sds data)

Checks if string is valid sticker or mpd sort type

Parameters
datasds string to check
Returns
bool true on success else false

◆ vcb_ismpdsort()

bool vcb_ismpdsort ( sds data)

Checks if string is a valid sort tag for mpd

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_ismpdstickertype()

bool vcb_ismpdstickertype ( sds data)

Checks if string is a valid MPD sticker type

Parameters
datasds string to check
Returns
true on success, else false

◆ vcb_ismpdtag()

bool vcb_ismpdtag ( sds data)

Checks if string is a valid MPD tag

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_ismpdtag_or_any()

bool vcb_ismpdtag_or_any ( sds data)

Checks if string is a valid MPD tag or special value "any"

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isname()

bool vcb_isname ( sds data)

Checks if string contains invalid chars Invalid chars are "\a\b\f\n\r\t\v"

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_ispathfilename()

bool vcb_ispathfilename ( sds data)

Checks if string is a valid path + filename

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isplaylistsort()

bool vcb_isplaylistsort ( sds data)

Checks if string is a valid sort tag for mpd

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isprint()

bool vcb_isprint ( sds data)

Checks if string is printable

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_issearchexpression_mympd()

bool vcb_issearchexpression_mympd ( sds data)

Checks if string is a valid song search expression supported by myMPD

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_issearchexpression_song()

bool vcb_issearchexpression_song ( sds data)

Checks if string is a valid song search expression

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_issearchexpression_webradio()

bool vcb_issearchexpression_webradio ( sds data)

Checks if string is a valid song search expression

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isstickername()

bool vcb_isstickername ( sds data)

Checks if string is a valid sticker name

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isstickerop()

bool vcb_isstickerop ( sds data)

Checks if string is a compare operator

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isstickersort()

bool vcb_isstickersort ( sds data)

Checks if string is a valid sticker sort type

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isstreamuri()

bool vcb_isstreamuri ( sds data)

Checks if string is a valid stream uri

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_istaglist()

bool vcb_istaglist ( sds data)

Checks if string is a valid comma separated list of tags

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_istext()

bool vcb_istext ( sds data)

Checks if string contains invalid chars Invalid chars are "\a\b\f\r\v"

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_isuri()

bool vcb_isuri ( sds data)

Checks if string is a valid uri or filepath

Parameters
datasds string to check
Returns
true on success else false

◆ vcb_iswebradiosort()

bool vcb_iswebradiosort ( sds data)

Checks if string is a valid sort tag for webradios

Parameters
datasds string to check
Returns
true on success else false

Variable Documentation

◆ invalid_filename_chars

const char* invalid_filename_chars = "\a\b\f\n\r\t\v/\\"
static

Invalid characters for filenmes

◆ invalid_filepath_chars

const char* invalid_filepath_chars = "\a\b\f\n\r\t\v"
static

Invalid characters for filepaths

◆ invalid_json_chars

const char* invalid_json_chars = "\a\b\f\v"
static

Private definitions Invalid characters for json strings

◆ invalid_name_chars

const char* invalid_name_chars = "\a\b\f\n\r\t\v"
static

Invalid characters for keys and names

◆ mympd_fields

const char* mympd_fields[]
static
Initial value:
={
"Value",
"Name", "Pos", "Duration", "Type", "Priority", "LastPlayed", "Filename", "Filetype",
"AudioFormat", "Last-Modified", "Lyrics", "Added", "Thumbnail",
"playCount", "skipCount", "lastPlayed", "lastSkipped", "like", "rating", "elapsed", "userDefinedSticker",
"Country", "Region", "Description", "Genres", "Homepage", "Languages", "Name", "StreamUri",
"Codec", "Bitrate",
"DiscCount", "SongCount",
0}

Valid fields for views