aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist/PlaylistSong.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-02-02 14:37:52 +0100
committerMax Kellermann <max@duempel.org>2014-02-03 23:32:10 +0100
commitca36ac2ba196ee2bbe4b54ee9a71d49174803277 (patch)
treed365b1ac7872e1785befdcebf254885c1c27a268 /src/playlist/PlaylistSong.cxx
parentba675d6a55769a6e82a6efaa2f4a812a4eea2362 (diff)
downloadmpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.tar.gz
mpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.tar.xz
mpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.zip
SongLoader: new class that merges duplicate code
There was quite a lot of duplicate code for loading DetachedSong objects, with different semantics for "securely" loading local files.
Diffstat (limited to 'src/playlist/PlaylistSong.cxx')
-rw-r--r--src/playlist/PlaylistSong.cxx67
1 files changed, 14 insertions, 53 deletions
diff --git a/src/playlist/PlaylistSong.cxx b/src/playlist/PlaylistSong.cxx
index b382994a6..e3defbddb 100644
--- a/src/playlist/PlaylistSong.cxx
+++ b/src/playlist/PlaylistSong.cxx
@@ -20,8 +20,7 @@
#include "config.h"
#include "PlaylistSong.hxx"
#include "Mapper.hxx"
-#include "db/DatabaseSong.hxx"
-#include "ls.hxx"
+#include "SongLoader.hxx"
#include "tag/Tag.hxx"
#include "tag/TagBuilder.hxx"
#include "fs/AllocatedPath.hxx"
@@ -65,44 +64,22 @@ apply_song_metadata(DetachedSong &dest, const DetachedSong &src)
}
static bool
-playlist_check_load_song(DetachedSong &song)
+playlist_check_load_song(DetachedSong &song, const SongLoader &loader)
{
- const char *const uri = song.GetURI();
-
- if (uri_has_scheme(uri)) {
- return true;
- } else if (PathTraitsUTF8::IsAbsolute(uri)) {
- DetachedSong tmp(uri);
- if (!tmp.Update())
- return false;
-
- apply_song_metadata(song, tmp);
- return true;
- } else {
-#ifdef ENABLE_DATABASE
- DetachedSong *tmp = DatabaseDetachSong(uri, IgnoreError());
- if (tmp == nullptr)
- return false;
-
- apply_song_metadata(song, *tmp);
- delete tmp;
- return true;
-#else
+ DetachedSong *tmp = loader.LoadSong(song.GetURI(), IgnoreError());
+ if (tmp == nullptr)
return false;
-#endif
- }
+
+ song.SetURI(tmp->GetURI());
+ apply_song_metadata(song, *tmp);
+ delete tmp;
+ return true;
}
bool
playlist_check_translate_song(DetachedSong &song, const char *base_uri,
- bool secure)
+ const SongLoader &loader)
{
- const char *const uri = song.GetURI();
-
- if (uri_has_scheme(uri))
- /* valid remote song? */
- return uri_supported_scheme(uri);
-
if (base_uri != nullptr && strcmp(base_uri, ".") == 0)
/* PathTraitsUTF8::GetParent() returns "." when there
is no directory name in the given path; clear that
@@ -110,26 +87,10 @@ playlist_check_translate_song(DetachedSong &song, const char *base_uri,
functions */
base_uri = nullptr;
- if (PathTraitsUTF8::IsAbsolute(uri)) {
- /* XXX fs_charset vs utf8? */
- const char *suffix = map_to_relative_path(uri);
- assert(suffix != nullptr);
-
- if (suffix != uri)
- song.SetURI(std::string(suffix));
- else if (!secure)
- /* local files must be relative to the music
- directory when "secure" is enabled */
- return false;
-
- base_uri = nullptr;
- }
-
- if (base_uri != nullptr) {
+ const char *uri = song.GetURI();
+ if (base_uri != nullptr && !uri_has_scheme(uri) &&
+ !PathTraitsUTF8::IsAbsolute(uri))
song.SetURI(PathTraitsUTF8::Build(base_uri, uri));
- /* repeat the above checks */
- return playlist_check_translate_song(song, nullptr, secure);
- }
- return playlist_check_load_song(song);
+ return playlist_check_load_song(song, loader);
}