Skip to content

Commit

Permalink
LocateUri: pass URI plugin kind, optionally disables plugin verify
Browse files Browse the repository at this point in the history
Commit b3a4583 added a LocateUri()
call to several playlist commands, which applied InputPlugin URI
scheme verification to playlist URIs.  This broke the SoundCloud
playlist plugin which uses "soundcloud://" URIs for which no input
plugin exists.

This commit allows the caller to specify the kind of plugin which
shall be used to verify the URI.  Right now, only "input" is
implemented; "storage" uses the "input" verification for now; and
"playlist" has no verification at all (for now).

Closes MusicPlayerDaemon#528
  • Loading branch information
MaxKellermann committed Apr 18, 2019
1 parent 7d814cc commit ead3dc6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 15 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ ver 0.21.8 (not yet released)
* output
- httpd: add missing mutex lock
- httpd: fix use-after-free bug
* playlist
- soundcloud: fix "Unsupported URI scheme" (0.21.6 regression)
* fix Bonjour bug
* fix build failure with GCC 9
* fix build failure with -Ddatabase=false
Expand Down
23 changes: 18 additions & 5 deletions src/LocateUri.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,26 @@ LocateFileUri(const char *uri, const Client *client
}

static LocatedUri
LocateAbsoluteUri(const char *uri
LocateAbsoluteUri(UriPluginKind kind, const char *uri
#ifdef ENABLE_DATABASE
, const Storage *storage
#endif
)
{
if (!uri_supported_scheme(uri))
throw std::runtime_error("Unsupported URI scheme");
switch (kind) {
case UriPluginKind::INPUT:
case UriPluginKind::STORAGE: // TODO: separate check for storage plugins
if (!uri_supported_scheme(uri))
throw std::runtime_error("Unsupported URI scheme");
break;

case UriPluginKind::PLAYLIST:
/* for now, no validation for playlist URIs; this is
more complicated because there are three ways to
identify which plugin to use: URI scheme, filename
suffix and MIME type */
break;
}

#ifdef ENABLE_DATABASE
if (storage != nullptr) {
Expand All @@ -76,7 +88,8 @@ LocateAbsoluteUri(const char *uri
}

LocatedUri
LocateUri(const char *uri, const Client *client
LocateUri(UriPluginKind kind,
const char *uri, const Client *client
#ifdef ENABLE_DATABASE
, const Storage *storage
#endif
Expand All @@ -100,7 +113,7 @@ LocateUri(const char *uri, const Client *client
#endif
);
else if (uri_has_scheme(uri))
return LocateAbsoluteUri(uri
return LocateAbsoluteUri(kind, uri
#ifdef ENABLE_DATABASE
, storage
#endif
Expand Down
9 changes: 8 additions & 1 deletion src/LocateUri.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Client;
class Storage;
#endif

enum class UriPluginKind {
INPUT,
STORAGE,
PLAYLIST,
};

struct LocatedUri {
enum class Type {
/**
Expand Down Expand Up @@ -84,7 +90,8 @@ struct LocatedUri {
* that feature is disabled if this parameter is nullptr
*/
LocatedUri
LocateUri(const char *uri, const Client *client
LocateUri(UriPluginKind kind,
const char *uri, const Client *client
#ifdef ENABLE_DATABASE
, const Storage *storage
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/SongLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ SongLoader::LoadSong(const char *uri_utf8) const
assert(uri_utf8 != nullptr);
#endif

const auto located_uri = LocateUri(uri_utf8, client
const auto located_uri = LocateUri(UriPluginKind::INPUT,
uri_utf8, client
#ifdef ENABLE_DATABASE
, storage
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/command/FileCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ handle_read_comments(Client &client, Request args, Response &r)

const char *const uri = args.front();

const auto located_uri = LocateUri(uri, &client
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri, &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down Expand Up @@ -331,7 +331,7 @@ handle_album_art(Client &client, Request args, Response &r)
const char *uri = args.front();
size_t offset = args.ParseUnsigned(1);

const auto located_uri = LocateUri(uri, &client
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri, &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/command/OtherCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ handle_listfiles(Client &client, Request args, Response &r)
/* default is root directory */
const auto uri = args.GetOptional(0, "");

const auto located_uri = LocateUri(uri, &client
const auto located_uri = LocateUri(UriPluginKind::STORAGE, uri, &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down Expand Up @@ -219,7 +219,7 @@ handle_lsinfo(Client &client, Request args, Response &r)
compatibility, work around this here */
uri = "";

const auto located_uri = LocateUri(uri, &client
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri, &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down
9 changes: 6 additions & 3 deletions src/command/PlaylistCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ handle_save(Client &client, Request args, gcc_unused Response &r)
CommandResult
handle_load(Client &client, Request args, gcc_unused Response &r)
{
const auto uri = LocateUri(args.front(), &client
const auto uri = LocateUri(UriPluginKind::PLAYLIST, args.front(),
&client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down Expand Up @@ -99,7 +100,8 @@ handle_load(Client &client, Request args, gcc_unused Response &r)
CommandResult
handle_listplaylist(Client &client, Request args, Response &r)
{
const auto name = LocateUri(args.front(), &client
const auto name = LocateUri(UriPluginKind::PLAYLIST, args.front(),
&client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand All @@ -115,7 +117,8 @@ handle_listplaylist(Client &client, Request args, Response &r)
CommandResult
handle_listplaylistinfo(Client &client, Request args, Response &r)
{
const auto name = LocateUri(args.front(), &client
const auto name = LocateUri(UriPluginKind::PLAYLIST, args.front(),
&client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/command/QueueCommands.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ handle_add(Client &client, Request args, Response &r)
here */
uri = "";

const auto located_uri = LocateUri(uri, &client
const auto located_uri = LocateUri(UriPluginKind::INPUT, uri,
&client
#ifdef ENABLE_DATABASE
, nullptr
#endif
Expand Down

0 comments on commit ead3dc6

Please sign in to comment.