Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ef24cfa5
Commit
ef24cfa5
authored
Oct 06, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/Plugin: add "prefixes"
parent
5d359832
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
73 additions
and
5 deletions
+73
-5
Registry.cxx
src/storage/Registry.cxx
+13
-1
Registry.hxx
src/storage/Registry.hxx
+4
-0
StoragePlugin.cxx
src/storage/StoragePlugin.cxx
+34
-0
StoragePlugin.hxx
src/storage/StoragePlugin.hxx
+9
-0
meson.build
src/storage/meson.build
+1
-0
CurlStorage.cxx
src/storage/plugins/CurlStorage.cxx
+5
-4
LocalStorage.cxx
src/storage/plugins/LocalStorage.cxx
+1
-0
NfsStorage.cxx
src/storage/plugins/NfsStorage.cxx
+3
-0
UdisksStorage.cxx
src/storage/plugins/UdisksStorage.cxx
+3
-0
No files found.
src/storage/Registry.cxx
View file @
ef24cfa5
...
...
@@ -58,13 +58,25 @@ GetStoragePluginByName(const char *name) noexcept
return
nullptr
;
}
const
StoragePlugin
*
GetStoragePluginByUri
(
const
char
*
uri
)
noexcept
{
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
{
const
StoragePlugin
&
plugin
=
**
i
;
if
(
plugin
.
SupportsUri
(
uri
))
return
*
i
;
}
return
nullptr
;
}
std
::
unique_ptr
<
Storage
>
CreateStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
for
(
auto
i
=
storage_plugins
;
*
i
!=
nullptr
;
++
i
)
{
const
StoragePlugin
&
plugin
=
**
i
;
if
(
plugin
.
create_uri
==
nullptr
)
if
(
plugin
.
create_uri
==
nullptr
||
!
plugin
.
SupportsUri
(
uri
)
)
continue
;
auto
storage
=
plugin
.
create_uri
(
event_loop
,
uri
);
...
...
src/storage/Registry.hxx
View file @
ef24cfa5
...
...
@@ -38,6 +38,10 @@ gcc_nonnull_all gcc_pure
const
StoragePlugin
*
GetStoragePluginByName
(
const
char
*
name
)
noexcept
;
gcc_nonnull_all
gcc_pure
const
StoragePlugin
*
GetStoragePluginByUri
(
const
char
*
uri
)
noexcept
;
gcc_nonnull_all
std
::
unique_ptr
<
Storage
>
CreateStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
);
...
...
src/storage/StoragePlugin.cxx
0 → 100644
View file @
ef24cfa5
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "StoragePlugin.hxx"
#include "util/StringCompare.hxx"
bool
StoragePlugin
::
SupportsUri
(
const
char
*
uri
)
const
noexcept
{
if
(
prefixes
==
nullptr
)
return
false
;
for
(
auto
i
=
prefixes
;
*
i
!=
nullptr
;
++
i
)
if
(
StringStartsWithIgnoreCase
(
uri
,
*
i
))
return
true
;
return
false
;
}
src/storage/StoragePlugin.hxx
View file @
ef24cfa5
...
...
@@ -29,10 +29,19 @@ struct StoragePlugin {
const
char
*
name
;
/**
* A nullptr-terminated list of URI prefixes handled by this
* plugin. This is usually a string in the form "scheme://".
*/
const
char
*
const
*
prefixes
;
/**
* Throws #std::runtime_error on error.
*/
std
::
unique_ptr
<
Storage
>
(
*
create_uri
)(
EventLoop
&
event_loop
,
const
char
*
uri
);
[[
gnu
::
pure
]]
bool
SupportsUri
(
const
char
*
uri
)
const
noexcept
;
};
#endif
src/storage/meson.build
View file @
ef24cfa5
storage_api = static_library(
'storage_api',
'StorageInterface.cxx',
'StoragePlugin.cxx',
include_directories: inc,
)
...
...
src/storage/plugins/CurlStorage.cxx
View file @
ef24cfa5
...
...
@@ -570,14 +570,15 @@ CurlStorage::OpenDirectory(std::string_view uri_utf8)
static
std
::
unique_ptr
<
Storage
>
CreateCurlStorageURI
(
EventLoop
&
event_loop
,
const
char
*
uri
)
{
if
(
!
StringStartsWithCaseASCII
(
uri
,
"http://"
)
&&
!
StringStartsWithCaseASCII
(
uri
,
"https://"
))
return
nullptr
;
return
std
::
make_unique
<
CurlStorage
>
(
event_loop
,
uri
);
}
static
constexpr
const
char
*
curl_prefixes
[]
=
{
"http://"
,
"https://"
,
nullptr
};
const
StoragePlugin
curl_storage_plugin
=
{
"curl"
,
curl_prefixes
,
CreateCurlStorageURI
,
};
src/storage/plugins/LocalStorage.cxx
View file @
ef24cfa5
...
...
@@ -173,4 +173,5 @@ CreateLocalStorage(Path base_fs)
constexpr
StoragePlugin
local_storage_plugin
=
{
"local"
,
nullptr
,
nullptr
,
};
src/storage/plugins/NfsStorage.cxx
View file @
ef24cfa5
...
...
@@ -425,7 +425,10 @@ CreateNfsStorageURI(EventLoop &event_loop, const char *base)
server
.
c_str
(),
mount
);
}
static
constexpr
const
char
*
nfs_prefixes
[]
=
{
"nfs://"
,
nullptr
};
const
StoragePlugin
nfs_storage_plugin
=
{
"nfs"
,
nfs_prefixes
,
CreateNfsStorageURI
,
};
src/storage/plugins/UdisksStorage.cxx
View file @
ef24cfa5
...
...
@@ -377,7 +377,10 @@ CreateUdisksStorageURI(EventLoop &event_loop, const char *base_uri)
std
::
move
(
inside_path
));
}
static
constexpr
const
char
*
udisks_prefixes
[]
=
{
"udisks://"
,
nullptr
};
const
StoragePlugin
udisks_storage_plugin
=
{
"udisks"
,
udisks_prefixes
,
CreateUdisksStorageURI
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment