db/DatabaseSong: make the Storage optional
Some database plugins don't use a Storage (e.g. UPnP), and with this plugin, DatabaseDetachSong() can crash.
This commit is contained in:
parent
f689e28958
commit
777e15bd78
|
@ -41,7 +41,7 @@ SongLoader::LoadFromDatabase(const char *uri) const
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
if (db != nullptr)
|
if (db != nullptr)
|
||||||
return DatabaseDetachSong(*db, *storage, uri);
|
return DatabaseDetachSong(*db, storage, uri);
|
||||||
#else
|
#else
|
||||||
(void)uri;
|
(void)uri;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -134,7 +134,7 @@ handle_searchaddpl(Client &client, Request args, Response &r)
|
||||||
|
|
||||||
const Database &db = client.GetDatabaseOrThrow();
|
const Database &db = client.GetDatabaseOrThrow();
|
||||||
|
|
||||||
search_add_to_playlist(db, *client.GetStorage(),
|
search_add_to_playlist(db, client.GetStorage(),
|
||||||
"", playlist, &filter);
|
"", playlist, &filter);
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,7 @@ handle_playlistadd(Client &client, Request args, gcc_unused Response &r)
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
const Database &db = client.GetDatabaseOrThrow();
|
const Database &db = client.GetDatabaseOrThrow();
|
||||||
|
|
||||||
search_add_to_playlist(db, *client.GetStorage(),
|
search_add_to_playlist(db, client.GetStorage(),
|
||||||
uri, playlist, nullptr);
|
uri, playlist, nullptr);
|
||||||
#else
|
#else
|
||||||
r.Error(ACK_ERROR_NO_EXIST, "directory or file not found");
|
r.Error(ACK_ERROR_NO_EXIST, "directory or file not found");
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
AddSong(const Storage &storage, const char *playlist_path_utf8,
|
AddSong(const Storage *storage, const char *playlist_path_utf8,
|
||||||
const LightSong &song)
|
const LightSong &song)
|
||||||
{
|
{
|
||||||
spl_append_song(playlist_path_utf8,
|
spl_append_song(playlist_path_utf8,
|
||||||
|
@ -36,14 +36,14 @@ AddSong(const Storage &storage, const char *playlist_path_utf8,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
search_add_to_playlist(const Database &db, const Storage &storage,
|
search_add_to_playlist(const Database &db, const Storage *storage,
|
||||||
const char *uri, const char *playlist_path_utf8,
|
const char *uri, const char *playlist_path_utf8,
|
||||||
const SongFilter *filter)
|
const SongFilter *filter)
|
||||||
{
|
{
|
||||||
const DatabaseSelection selection(uri, true, filter);
|
const DatabaseSelection selection(uri, true, filter);
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
const auto f = std::bind(AddSong, std::ref(storage),
|
const auto f = std::bind(AddSong, storage,
|
||||||
playlist_path_utf8, _1);
|
playlist_path_utf8, _1);
|
||||||
db.Visit(selection, f);
|
db.Visit(selection, f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SongFilter;
|
||||||
|
|
||||||
gcc_nonnull(3,4)
|
gcc_nonnull(3,4)
|
||||||
void
|
void
|
||||||
search_add_to_playlist(const Database &db, const Storage &storage,
|
search_add_to_playlist(const Database &db, const Storage *storage,
|
||||||
const char *uri, const char *path_utf8,
|
const char *uri, const char *path_utf8,
|
||||||
const SongFilter *filter);
|
const SongFilter *filter);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
static void
|
static void
|
||||||
AddToQueue(Partition &partition, const LightSong &song)
|
AddToQueue(Partition &partition, const LightSong &song)
|
||||||
{
|
{
|
||||||
const Storage &storage = *partition.instance.storage;
|
const auto *storage = partition.instance.storage;
|
||||||
partition.playlist.AppendSong(partition.pc,
|
partition.playlist.AppendSong(partition.pc,
|
||||||
DatabaseDetachSong(storage,
|
DatabaseDetachSong(storage,
|
||||||
song));
|
song));
|
||||||
|
|
|
@ -28,21 +28,21 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
DetachedSong
|
DetachedSong
|
||||||
DatabaseDetachSong(const Storage &storage, const LightSong &song)
|
DatabaseDetachSong(const Storage *storage, const LightSong &song)
|
||||||
{
|
{
|
||||||
DetachedSong detached(song);
|
DetachedSong detached(song);
|
||||||
assert(detached.IsInDatabase());
|
assert(detached.IsInDatabase());
|
||||||
|
|
||||||
if (!detached.HasRealURI()) {
|
if (!detached.HasRealURI() && storage != nullptr) {
|
||||||
const auto uri = song.GetURI();
|
const auto uri = song.GetURI();
|
||||||
detached.SetRealURI(storage.MapUTF8(uri.c_str()));
|
detached.SetRealURI(storage->MapUTF8(uri.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return detached;
|
return detached;
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachedSong
|
DetachedSong
|
||||||
DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri)
|
DatabaseDetachSong(const Database &db, const Storage *storage, const char *uri)
|
||||||
{
|
{
|
||||||
const LightSong *tmp = db.GetSong(uri);
|
const LightSong *tmp = db.GetSong(uri);
|
||||||
assert(tmp != nullptr);
|
assert(tmp != nullptr);
|
||||||
|
|
|
@ -33,7 +33,7 @@ class DetachedSong;
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
DetachedSong
|
DetachedSong
|
||||||
DatabaseDetachSong(const Storage &storage, const LightSong &song);
|
DatabaseDetachSong(const Storage *storage, const LightSong &song);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a song in the database and convert it to a #DetachedSong
|
* Look up a song in the database and convert it to a #DetachedSong
|
||||||
|
@ -43,7 +43,7 @@ DatabaseDetachSong(const Storage &storage, const LightSong &song);
|
||||||
*/
|
*/
|
||||||
gcc_pure
|
gcc_pure
|
||||||
DetachedSong
|
DetachedSong
|
||||||
DatabaseDetachSong(const Database &db, const Storage &storage,
|
DatabaseDetachSong(const Database &db, const Storage *storage,
|
||||||
const char *uri);
|
const char *uri);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -109,7 +109,7 @@ static const char *uri2 = "foo/bar.ogg";
|
||||||
|
|
||||||
DetachedSong
|
DetachedSong
|
||||||
DatabaseDetachSong(gcc_unused const Database &db,
|
DatabaseDetachSong(gcc_unused const Database &db,
|
||||||
gcc_unused const Storage &_storage,
|
gcc_unused const Storage *_storage,
|
||||||
const char *uri)
|
const char *uri)
|
||||||
{
|
{
|
||||||
if (strcmp(uri, uri2) == 0)
|
if (strcmp(uri, uri2) == 0)
|
||||||
|
|
Loading…
Reference in New Issue