From 2f376fbc7a7a31945a2fc448d1be4627f82318ef Mon Sep 17 00:00:00 2001 From: emeric Date: Wed, 20 Aug 2014 14:32:22 +0200 Subject: [PATCH] Adding artist/release/track max name length checks. NOT TESTED --- TODO | 12 +++++------- database/Artist.cpp | 4 ++-- database/AudioTypes.hpp | 10 +++++++++- database/Genre.cpp | 4 ++-- database/Release.cpp | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index b0ce8da0..396f8968 100644 --- a/TODO +++ b/TODO @@ -21,11 +21,9 @@ - Implement a video database cleanup - Group video in "video groups". Each video may has sub groups (current "Path" class) -> Simplify database and remove the Path class -- Use size limits for strings (artist, release, genre)? - Process only files whose extensions are well known in audio/video world (avoid useless parsing/errors)? [Metadata] -- Skip trailing non printable characters (spaces) in track name, artist, etc. [Transcode] - some zombies seem to be remaining after a week of use @@ -43,20 +41,20 @@ - Prefered codecs for audio/video? [Audio] + - Search patterns in the genre list - ReleaseView/ArtistView/GenreView: -> Track count for this special category. Easier: add a special entry '' that contains everything? - MediaPlayer: move slider using js (http://redmine.webtoolkit.eu/boards/2/topics/7924?r=8478) - TrackView : handle original release date - TrackView : handle duration > 1 hour - TrackView : select only relevant columns to speed up queries (do not get eveything) - TrackView : Reselect the current selected item when displaying the updated search results - - ReleaseView: display the release's publication year + - ReleaseView: display the original release's publication year - OGG metadata -> properly handle metadata nested in the audio stream - - TrackView : when udating the view, reselect the current playing track - Filters: use directly the id as constraint, instead of the name? - Implement a playlist: - - Drag and drop all objets from the views (genre, artist, release, track) in the playlist? - - Add 'play/add last' button on mouse hover? - - Save/Load playlists? + - Drag and drop all objets from the views (genre, artist, release, track) in the playlist? + - Add 'play/add last' button on mouse hover? + - Save/Load playlists? [Video] - View the Videos in a WtTableView ? diff --git a/database/Artist.cpp b/database/Artist.cpp index 00312d9e..fd028c0c 100644 --- a/database/Artist.cpp +++ b/database/Artist.cpp @@ -4,7 +4,7 @@ namespace Database { Artist::Artist(const std::string& name) -: _name(name) +: _name(std::string(name, 0 , _maxNameLength)) { } @@ -12,7 +12,7 @@ Artist::Artist(const std::string& name) Artist::pointer Artist::getByName(Wt::Dbo::Session& session, const std::string& name) { - return session.find().where("name = ?").bind( name ); + return session.find().where("name = ?").bind( std::string(name, 0, _maxNameLength) ); } // Create diff --git a/database/AudioTypes.hpp b/database/AudioTypes.hpp index 52d2caa6..27a00bc1 100644 --- a/database/AudioTypes.hpp +++ b/database/AudioTypes.hpp @@ -51,6 +51,9 @@ class Artist private: + + static const std::size_t _maxNameLength = 128; + std::string _name; Wt::Dbo::collection< Wt::Dbo::ptr > _tracks; // Tracks of this artist @@ -93,6 +96,7 @@ class Release } private: + static const std::size_t _maxNameLength = 128; std::string _name; Wt::Dbo::collection< Wt::Dbo::ptr > _tracks; // Tracks in the release @@ -130,6 +134,7 @@ class Genre } private: + static const std::size_t _maxNameLength = 128; std::string _name; Wt::Dbo::collection< Wt::Dbo::ptr > _tracks; @@ -161,7 +166,7 @@ class Track // Accessors void setTrackNumber(int num) { _trackNumber = num; } void setDiscNumber(int num) { _discNumber = num; } - void setName(const std::string& name) { _name = name; } + void setName(const std::string& name) { _name = std::string(name, 0, _maxNameLength); } void setDuration(boost::posix_time::time_duration duration) { _duration = duration; } void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; } void setChecksum(const std::vector& checksum) { _fileChecksum = checksum; } @@ -203,6 +208,9 @@ class Track } private: + + static const std::size_t _maxNameLength = 128; + int _trackNumber; int _discNumber; std::string _name; diff --git a/database/Genre.cpp b/database/Genre.cpp index ca0cedfd..ac93a9ce 100644 --- a/database/Genre.cpp +++ b/database/Genre.cpp @@ -7,7 +7,7 @@ Genre::Genre() } Genre::Genre(const std::string& name) -: _name( name ) +: _name( std::string(name, 0, _maxNameLength) ) { } @@ -16,7 +16,7 @@ Genre::pointer Genre::getByName(Wt::Dbo::Session& session, const std::string& name) { // TODO use like search - return session.find().where("name = ?").bind( name ); + return session.find().where("name = ?").bind( std::string(name, 0, _maxNameLength) ); } Genre::pointer diff --git a/database/Release.cpp b/database/Release.cpp index ef7ec109..1a7cb241 100644 --- a/database/Release.cpp +++ b/database/Release.cpp @@ -7,14 +7,14 @@ namespace Database { Release::Release(const std::string& name) -: _name(name) +: _name(std::string(name, 0, _maxNameLength)) { } Release::pointer Release::getByName(Wt::Dbo::Session& session, const std::string& name) { - return session.find().where("name = ?").bind( name ); + return session.find().where("name = ?").bind( std::string(name, 0, _maxNameLength) ); } Release::pointer