Registry.cxx 1.96 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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 "Registry.hxx"
#include "StoragePlugin.hxx"
22
#include "StorageInterface.hxx"
23
#include "plugins/LocalStorage.hxx"
24
#include "plugins/UdisksStorage.hxx"
25
#include "plugins/SmbclientStorage.hxx"
26
#include "plugins/NfsStorage.hxx"
27
#include "plugins/CurlStorage.hxx"
28
#include "config.h"
29 30 31

#include <string.h>

32
constexpr const StoragePlugin *storage_plugins[] = {
33 34 35
	&local_storage_plugin,
#ifdef ENABLE_SMBCLIENT
	&smbclient_storage_plugin,
36
#endif
37 38 39
#ifdef ENABLE_UDISKS
	&udisks_storage_plugin,
#endif
40 41
#ifdef ENABLE_NFS
	&nfs_storage_plugin,
42 43 44
#endif
#ifdef ENABLE_WEBDAV
	&curl_storage_plugin,
45 46 47 48 49
#endif
	nullptr
};

const StoragePlugin *
50
GetStoragePluginByName(const char *name) noexcept
51 52 53 54 55 56 57 58 59 60
{
	for (auto i = storage_plugins; *i != nullptr; ++i) {
		const StoragePlugin &plugin = **i;
		if (strcmp(plugin.name, name) == 0)
			return *i;
	}

	return nullptr;
}

61
std::unique_ptr<Storage>
62
CreateStorageURI(EventLoop &event_loop, const char *uri)
63 64 65 66 67 68 69
{
	for (auto i = storage_plugins; *i != nullptr; ++i) {
		const StoragePlugin &plugin = **i;

		if (plugin.create_uri == nullptr)
			continue;

70
		auto storage = plugin.create_uri(event_loop, uri);
71
		if (storage != nullptr)
72 73 74 75 76
			return storage;
	}

	return nullptr;
}