From a0088ccce1749dbef6503fbf489f7096d824c11d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 5 Feb 2014 19:23:02 +0100 Subject: storage: add struct StoragePlugin and a plugin registry --- src/storage/plugins/LocalStorage.cxx | 6 ++++++ src/storage/plugins/LocalStorage.hxx | 3 +++ src/storage/plugins/SmbclientStorage.cxx | 13 +++++++++++-- src/storage/plugins/SmbclientStorage.hxx | 6 ++---- 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src/storage/plugins') 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 -- cgit v1.2.3