From 155bb1c6cc1227232e0c50469f31bed9c06497f3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 12 Jan 2016 02:22:15 +0000 Subject: Basic support for configuring the client just with a URL --- netfs/fuse/fuseApp.cpp | 37 +++++++++++++++++++++++++++++++------ netfs/fuse/fuseApp.h | 8 ++++++-- netfs/unittests/testCore.cpp | 15 +++++++++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 4766360..d05bcc0 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace AdHoc { template class Cache; @@ -69,13 +70,33 @@ void * NetFS::FuseApp::init(struct fuse_conn_info *) { ic = Ice::initialize(args); + fcr = configurator(); + return NULL; +} + +NetFS::Client::ResourcePtr +NetFS::FuseApp::configureFromFile(const std::string & configPath, const std::string & resourceName) const +{ auto fc = ReadConfiguration(configPath); auto e = fc->Resources.find(resourceName); if (e == fc->Resources.end()) { throw std::runtime_error("No such resource: " + resourceName); } - fcr = e->second; - return NULL; + return e->second; +} + +NetFS::Client::ResourcePtr +NetFS::FuseApp::configureFromUri(const std::string & uriString) const +{ + AdHoc::Uri uri(uriString); + + NetFS::Client::ResourcePtr r = new NetFS::Client::Resource(); + r->ExportName = uri.path->string(); + r->Endpoints.push_back(stringbf("%s -h %s -p %d", uri.scheme, uri.host, uri.port ? *uri.port : 4000)); + if (uri.password) { + r->AuthToken = *uri.password; + } + return r; } int @@ -90,10 +111,14 @@ NetFS::FuseApp::opt_parse(void *, const char * arg, int, struct fuse_args *) else if (arg[0] == '-') { return 1; } - else if (resourceName.empty()) { - const char * colon = strchr(arg, ':'); - resourceName = colon + 1; - configPath.assign(arg, colon); + else if (!configurator) { + if (strstr(arg, "://")) { + configurator = boost::bind(&NetFS::FuseApp::configureFromUri, this, arg); + } + else { + const char * colon = strchr(arg, ':'); + configurator = boost::bind(&NetFS::FuseApp::configureFromFile, this, std::string(arg, colon), colon + 1); + } return 0; } else if (mountPoint.empty()) { diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index 3e9f1c4..a97d271 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -2,6 +2,7 @@ #define NETFS_FUSE_H #include +#include #include #include #include @@ -85,9 +86,14 @@ namespace NetFS { virtual struct fuse_context * fuse_get_context() = 0; protected: + typedef boost::function Configurator; + Configurator configurator; virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const; + virtual NetFS::Client::ResourcePtr configureFromFile(const std::string &, const std::string &) const; + virtual NetFS::Client::ResourcePtr configureFromUri(const std::string &) const; private: + void setProxy(OpenFilePtr, uint64_t & fh); OpenFilePtr getFileProxy(uint64_t localID) const; void clearFileProxy(uint64_t localID); @@ -109,8 +115,6 @@ namespace NetFS { bool sessionOpened; std::string mountPoint; - std::string resourceName; - std::string configPath; OpenDirs openDirs; int openDirID; diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index c18f1cb..27a5cf4 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -6,6 +6,7 @@ #include const std::string testEndpoint("tcp -h localhost -p 12012"); +const std::string testUri("tcp://localhost:12012/testvol"); class Core { public: @@ -77,3 +78,17 @@ BOOST_AUTO_TEST_CASE( testNoAuthWithPass ) BOOST_REQUIRE_EQUAL(0, c.fuse->statfs("/", &s)); } +BOOST_AUTO_TEST_CASE( uriConnect ) +{ + MockDaemonHost daemon(testEndpoint, { + "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string() + }); + FuseMockHost fuse(std::string(), { + testUri, + (rootDir / "test").string(), + }); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); +} + -- cgit v1.2.3