summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-01-12 02:22:15 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-01-12 02:22:15 +0000
commit155bb1c6cc1227232e0c50469f31bed9c06497f3 (patch)
tree2f4b0db1113d0271f70ef9bd9d65a1d92b2173a4
parentUse definedDirs (diff)
downloadnetfs-1.1.5.3.tar.bz2
netfs-1.1.5.3.tar.xz
netfs-1.1.5.3.zip
Basic support for configuring the client just with a URLnetfs-1.1.5.3
-rw-r--r--netfs/fuse/fuseApp.cpp37
-rw-r--r--netfs/fuse/fuseApp.h8
-rw-r--r--netfs/unittests/testCore.cpp15
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 <entCache.h>
#include <slicer/slicer.h>
#include <xml/serializer.h>
+#include <uriParse.h>
namespace AdHoc {
template class Cache<struct stat, std::string>;
@@ -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 <boost/thread/shared_mutex.hpp>
+#include <boost/function.hpp>
#include <Ice/Ice.h>
#include <Glacier2/Session.h>
#include <service.h>
@@ -85,9 +86,14 @@ namespace NetFS {
virtual struct fuse_context * fuse_get_context() = 0;
protected:
+ typedef boost::function<Client::ResourcePtr()> 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 <boost/filesystem/path.hpp>
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));
+}
+