diff options
author | jcoalson <jcoalson> | 2004-12-30 03:41:19 +0000 |
---|---|---|
committer | jcoalson <jcoalson> | 2004-12-30 03:41:19 +0000 |
commit | a21dd8c5d82a0b13e49d3ef3ea1c080f68155e3c (patch) | |
tree | 9b9e8ff1895ca3a41c43df078cc064935e161e95 /src/libFLAC/format.c | |
parent | 0b93717b3e1b02d3d03c513aa2965327664416a4 (diff) | |
download | flac-arm-1.1.3-a21dd8c5d82a0b13e49d3ef3ea1c080f68155e3c.tar.gz |
add vorbiscomment validation functions to format.c and test code; validate name part of vorbiscomment in metadata and metadata++ interfaces
Diffstat (limited to 'src/libFLAC/format.c')
-rw-r--r-- | src/libFLAC/format.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/libFLAC/format.c b/src/libFLAC/format.c index d4ac5acb..d149928c 100644 --- a/src/libFLAC/format.c +++ b/src/libFLAC/format.c @@ -254,6 +254,77 @@ FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *se return j; } +static __inline unsigned utf8len_(const FLAC__byte *utf8) +{ + FLAC__ASSERT(0 != utf8); + if ((utf8[0] & 0x80) == 0) + return 1; + else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) + return 2; + else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) + return 3; + else + return 0; +} + +FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name) +{ + char c; + for(c = *name; c; c = *(++name)) + if(c < 0x20 || c == 0x3d || c > 0x7d) + return false; + return true; +} + +FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length) +{ + if(length == (unsigned)(-1)) { + while(*value) { + unsigned n = utf8len_(value); + if(n == 0) + return false; + value += n; + } + } + else { + const FLAC__byte *end = value + length; + while(value < end) { + unsigned n = utf8len_(value); + if(n == 0) + return false; + value += n; + } + if(value != end) + return false; + } + return true; +} + +FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length) +{ + const FLAC__byte *s, *end; + + for(s = entry, end = s + length; s < end && *s != '='; s++) { + if(*s < 0x20 || *s > 0x7D) + return false; + } + if(s == end) + return false; + + s++; /* skip '=' */ + + while(s < end) { + unsigned n = utf8len_(s); + if(n == 0) + return false; + s += n; + } + if(s != end) + return false; + + return true; +} + FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation) { unsigned i, j; |