LocateUri: implement UriPluginKind::STORAGE properly

This way, URI schemes supported by arbitrary storage plugins are
allowed.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1270
This commit is contained in:
Max Kellermann 2021-10-06 20:15:20 +02:00
parent ef24cfa523
commit cf554d306d
2 changed files with 11 additions and 1 deletions

1
NEWS
View File

@ -2,6 +2,7 @@ ver 0.23 (not yet released)
* protocol * protocol
- new command "getvol" - new command "getvol"
- show the audio format in "playlistinfo" - show the audio format in "playlistinfo"
- support "listfiles" with arbitrary storage plugins
* database * database
- proxy: require MPD 0.20 or later - proxy: require MPD 0.20 or later
- proxy: require libmpdclient 2.11 or later - proxy: require libmpdclient 2.11 or later

View File

@ -22,6 +22,7 @@
#include "client/Client.hxx" #include "client/Client.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"
#include "ls.hxx" #include "ls.hxx"
#include "storage/Registry.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/UriExtract.hxx" #include "util/UriExtract.hxx"
@ -67,11 +68,15 @@ LocateAbsoluteUri(UriPluginKind kind, const char *uri
{ {
switch (kind) { switch (kind) {
case UriPluginKind::INPUT: case UriPluginKind::INPUT:
case UriPluginKind::STORAGE: // TODO: separate check for storage plugins
if (!uri_supported_scheme(uri)) if (!uri_supported_scheme(uri))
throw std::invalid_argument("Unsupported URI scheme"); throw std::invalid_argument("Unsupported URI scheme");
break; break;
case UriPluginKind::STORAGE:
/* plugin support will be checked after the
Storage::MapToRelativeUTF8() call */
break;
case UriPluginKind::PLAYLIST: case UriPluginKind::PLAYLIST:
/* for now, no validation for playlist URIs; this is /* for now, no validation for playlist URIs; this is
more complicated because there are three ways to more complicated because there are three ways to
@ -88,6 +93,10 @@ LocateAbsoluteUri(UriPluginKind kind, const char *uri
return LocatedUri(LocatedUri::Type::RELATIVE, return LocatedUri(LocatedUri::Type::RELATIVE,
suffix.data()); suffix.data());
} }
if (kind == UriPluginKind::STORAGE &&
GetStoragePluginByUri(uri) == nullptr)
throw std::invalid_argument("Unsupported URI scheme");
#endif #endif
return LocatedUri(LocatedUri::Type::ABSOLUTE, uri); return LocatedUri(LocatedUri::Type::ABSOLUTE, uri);