diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | src/CommandLine.cxx | 8 | ||||
-rw-r--r-- | src/storage/Registry.cxx | 67 | ||||
-rw-r--r-- | src/storage/Registry.hxx | 44 | ||||
-rw-r--r-- | src/storage/StoragePlugin.hxx | 34 | ||||
-rw-r--r-- | src/storage/plugins/LocalStorage.cxx | 6 | ||||
-rw-r--r-- | src/storage/plugins/LocalStorage.hxx | 3 | ||||
-rw-r--r-- | src/storage/plugins/SmbclientStorage.cxx | 13 | ||||
-rw-r--r-- | src/storage/plugins/SmbclientStorage.hxx | 6 |
9 files changed, 177 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am index 2e5d8b613..8fc6f23d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -425,6 +425,8 @@ if ENABLE_DATABASE noinst_LIBRARIES += libstorage.a libstorage_a_SOURCES = \ + src/storage/StoragePlugin.hxx \ + src/storage/Registry.cxx src/storage/Registry.hxx \ src/storage/StorageInterface.cxx src/storage/StorageInterface.hxx \ src/storage/plugins/LocalStorage.cxx src/storage/plugins/LocalStorage.hxx \ src/storage/FileInfo.hxx diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 69af68495..cc278c0fd 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -43,6 +43,8 @@ #ifdef ENABLE_DATABASE #include "db/Registry.hxx" #include "db/DatabasePlugin.hxx" +#include "storage/Registry.hxx" +#include "storage/StoragePlugin.hxx" #endif #ifdef ENABLE_NEIGHBOR_PLUGINS @@ -113,6 +115,12 @@ static void version(void) for (auto i = database_plugins; *i != nullptr; ++i) printf(" %s", (*i)->name); + + puts("\n\n" + "Storage plugins:"); + + for (auto i = storage_plugins; *i != nullptr; ++i) + printf(" %s", (*i)->name); #endif #ifdef ENABLE_NEIGHBOR_PLUGINS diff --git a/src/storage/Registry.cxx b/src/storage/Registry.cxx new file mode 100644 index 000000000..b81349510 --- /dev/null +++ b/src/storage/Registry.cxx @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2003-2014 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 "config.h" +#include "Registry.hxx" +#include "StoragePlugin.hxx" +#include "plugins/LocalStorage.hxx" +#include "plugins/SmbclientStorage.hxx" +#include "util/Error.hxx" + +#include <assert.h> +#include <string.h> + +const StoragePlugin *const storage_plugins[] = { + &local_storage_plugin, +#ifdef ENABLE_SMBCLIENT + &smbclient_storage_plugin, +#endif + nullptr +}; + +const StoragePlugin * +GetStoragePluginByName(const char *name) +{ + for (auto i = storage_plugins; *i != nullptr; ++i) { + const StoragePlugin &plugin = **i; + if (strcmp(plugin.name, name) == 0) + return *i; + } + + return nullptr; +} + +Storage * +CreateStorageURI(const char *uri, Error &error) +{ + assert(!error.IsDefined()); + + for (auto i = storage_plugins; *i != nullptr; ++i) { + const StoragePlugin &plugin = **i; + + if (plugin.create_uri == nullptr) + continue; + + Storage *storage = plugin.create_uri(uri, error); + if (storage != nullptr || error.IsDefined()) + return storage; + } + + return nullptr; +} diff --git a/src/storage/Registry.hxx b/src/storage/Registry.hxx new file mode 100644 index 000000000..9696b3de1 --- /dev/null +++ b/src/storage/Registry.hxx @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2003-2014 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. + */ + +#ifndef MPD_STORAGE_REGISTRY_HXX +#define MPD_STORAGE_REGISTRY_HXX + +#include "check.h" +#include "Compiler.h" + +struct StoragePlugin; +class Storage; +class Error; + +/** + * nullptr terminated list of all storage plugins which were enabled at + * compile time. + */ +extern const StoragePlugin *const storage_plugins[]; + +gcc_nonnull_all gcc_pure +const StoragePlugin * +GetStoragePluginByName(const char *name); + +gcc_nonnull_all gcc_malloc +Storage * +CreateStorageURI(const char *uri, Error &error); + +#endif diff --git a/src/storage/StoragePlugin.hxx b/src/storage/StoragePlugin.hxx new file mode 100644 index 000000000..d91caf24b --- /dev/null +++ b/src/storage/StoragePlugin.hxx @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2003-2014 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. + */ + +#ifndef MPD_STORAGE_PLUGIN_HXX +#define MPD_STORAGE_PLUGIN_HXX + +#include "check.h" + +class Error; +class Storage; + +struct StoragePlugin { + const char *name; + + Storage *(*create_uri)(const char *uri, Error &error); +}; + +#endif diff --git a/src/storage/plugins/LocalStorage.cxx b/src/storage/plugins/LocalStorage.cxx index 2bf430b2e..34d11569c 100644 --- a/src/storage/plugins/LocalStorage.cxx +++ b/src/storage/plugins/LocalStorage.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "LocalStorage.hxx" +#include "storage/StoragePlugin.hxx" #include "storage/StorageInterface.hxx" #include "storage/FileInfo.hxx" #include "util/Error.hxx" @@ -210,3 +211,8 @@ CreateLocalStorage(Path base_fs) { return new LocalStorage(base_fs); } + +const StoragePlugin local_storage_plugin = { + "local", + nullptr, +}; diff --git a/src/storage/plugins/LocalStorage.hxx b/src/storage/plugins/LocalStorage.hxx index e80fd8276..7295d38e7 100644 --- a/src/storage/plugins/LocalStorage.hxx +++ b/src/storage/plugins/LocalStorage.hxx @@ -23,9 +23,12 @@ #include "check.h" #include "Compiler.h" +struct StoragePlugin; class Storage; class Path; +extern const StoragePlugin local_storage_plugin; + gcc_malloc gcc_nonnull_all Storage * CreateLocalStorage(Path base_fs); diff --git a/src/storage/plugins/SmbclientStorage.cxx b/src/storage/plugins/SmbclientStorage.cxx index 6d61ab75e..a73c8d65c 100644 --- a/src/storage/plugins/SmbclientStorage.cxx +++ b/src/storage/plugins/SmbclientStorage.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "SmbclientStorage.hxx" +#include "storage/StoragePlugin.hxx" #include "storage/StorageInterface.hxx" #include "storage/FileInfo.hxx" #include "lib/smbclient/Init.hxx" @@ -178,9 +179,12 @@ SmbclientDirectoryReader::GetInfo(gcc_unused bool follow, FileInfo &info, return ::GetInfo(path.c_str(), info, error); } -Storage * -CreateSmbclientStorage(const char *base, Error &error) +static Storage * +CreateSmbclientStorageURI(const char *base, Error &error) { + if (memcmp(base, "smb://", 6) != 0) + return nullptr; + if (!SmbclientInit(error)) return nullptr; @@ -200,3 +204,8 @@ CreateSmbclientStorage(const char *base, Error &error) return new SmbclientStorage(base, ctx2); } + +const StoragePlugin smbclient_storage_plugin = { + "smbclient", + CreateSmbclientStorageURI, +}; diff --git a/src/storage/plugins/SmbclientStorage.hxx b/src/storage/plugins/SmbclientStorage.hxx index 3a77ebf1d..7c198d920 100644 --- a/src/storage/plugins/SmbclientStorage.hxx +++ b/src/storage/plugins/SmbclientStorage.hxx @@ -22,10 +22,8 @@ #include "check.h" -class Error; -class Storage; +struct StoragePlugin; -Storage * -CreateSmbclientStorage(const char *base, Error &error); +extern const StoragePlugin smbclient_storage_plugin; #endif |