Add runtime enumeration of supported schemas.

Fix src/ls.cxx to only print unique schemas.
Refactor src/ls.cxx to use src/input/InputPlugin functionality.

Add dynamic enumeration support to curl plugin.
This commit is contained in:
Eugene Gorodinsky
2019-04-17 21:47:55 +03:00
committed by Eugene Gorodinsky
parent 38d0f02e83
commit 4e2a551f30
12 changed files with 137 additions and 32 deletions

View File

@@ -22,6 +22,9 @@
#include "Ptr.hxx"
#include "util/Compiler.h"
#include <assert.h>
#include <set>
#include <string>
struct ConfigBlock;
class Mutex;
@@ -62,6 +65,11 @@ struct InputPlugin {
*/
InputStreamPtr (*open)(const char *uri, Mutex &mutex);
/**
* return a set of supported protocols
*/
std::set<std::string> (*protocols)();
/**
* Prepare a #RemoteTagScanner. The operation must be started
* using RemoteTagScanner::Start(). Returns nullptr if the
@@ -76,6 +84,25 @@ struct InputPlugin {
gcc_pure
bool SupportsUri(const char *uri) const noexcept;
template<typename F>
void ForeachSupportedUri(F lambda) const noexcept {
assert(prefixes || protocols);
if (prefixes != nullptr) {
for (auto schema = prefixes; *schema != nullptr; ++schema) {
lambda(*schema);
}
}
if (protocols != nullptr) {
for (auto schema : protocols()) {
lambda(schema.c_str());
}
}
}
};
bool
protocol_is_whitelisted(const char *proto);
#endif