From 45ff0b506dfa95f097cfaee37ec09cda8e3d3ec0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Apr 2020 10:16:12 +0100 Subject: Configure settings from URI params --- netfs/fuse/fuseApp.cpp | 13 ++++++++++--- netfs/fuse/fuseApp.h | 5 ++--- netfs/unittests/testFuse.cpp | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index fd26516..29820b8 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -10,6 +10,7 @@ #include #include "fuseDirs.h" #include "fuseFiles.h" +#include namespace AdHoc { template class Cache; @@ -87,7 +88,7 @@ NetFS::FuseApp::init(struct fuse_conn_info *, struct fuse_config *) } NetFS::Client::ResourcePtr -NetFS::FuseApp::configureFromFile(const std::filesystem::path & path, const std::string & resourceName) const +NetFS::FuseApp::configureFromFile(const std::filesystem::path & path, const std::string & resourceName) { auto s = Slicer::FileDeserializerFactory::createNew(path.extension().string(), path); auto c = Slicer::DeserializeAnyWith(s); @@ -96,9 +97,9 @@ NetFS::FuseApp::configureFromFile(const std::filesystem::path & path, const std: AdHocFormatter(IceEndpointFmt, "%? -h %? -p %?"); NetFS::Client::ResourcePtr -NetFS::FuseApp::configureFromUri(const std::string & uriString) const +NetFS::FuseApp::configureFromUri(const std::string & uriString) { - AdHoc::Uri uri(uriString); + const AdHoc::Uri uri(uriString); auto r = std::make_shared(); r->ExportName = uri.path->string(); @@ -106,6 +107,12 @@ NetFS::FuseApp::configureFromUri(const std::string & uriString) const if (uri.password) { r->AuthToken = *uri.password; } + auto set = [&uri](const auto & param, auto & setting) { + if (auto p = uri.query.find(param); p != uri.query.end()) { + setting = boost::lexical_cast>(p->second); + } + }; + set("async", r->Async); return r; } diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index bef757b..6869c01 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -79,9 +79,8 @@ namespace NetFS { virtual struct fuse_context * fuse_get_context() = 0; - protected: - NetFS::Client::ResourcePtr configureFromFile(const std::filesystem::path &, const std::string &) const; - NetFS::Client::ResourcePtr configureFromUri(const std::string &) const; + static NetFS::Client::ResourcePtr configureFromFile(const std::filesystem::path &, const std::string &); + static NetFS::Client::ResourcePtr configureFromUri(const std::string &); protected: template diff --git a/netfs/unittests/testFuse.cpp b/netfs/unittests/testFuse.cpp index 5d97642..b856e15 100644 --- a/netfs/unittests/testFuse.cpp +++ b/netfs/unittests/testFuse.cpp @@ -134,3 +134,21 @@ BOOST_AUTO_TEST_CASE(fuse_ls, * boost::unit_test::timeout(5)) BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_CASE(url_params_non) +{ + auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo"); + BOOST_CHECK_EQUAL(fcs->Async, false); +} + +BOOST_AUTO_TEST_CASE(url_params_1) +{ + auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?async=1"); + BOOST_CHECK_EQUAL(fcs->Async, true); +} + +BOOST_AUTO_TEST_CASE(url_params_2) +{ + auto fcs = NetFS::FuseApp::configureFromUri("tcp://localhost/foo?0&async=0"); + BOOST_CHECK_EQUAL(fcs->Async, false); +} + -- cgit v1.2.3