summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-10-25 20:41:57 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-12-16 20:39:53 +0000
commitbfe3b02646e0b34562b28a3771f19b8a265f0856 (patch)
tree1f4cc8f53cc678db99be95db5f497019598258e6
parentConfiguration types can be local with modern Slicer (diff)
downloadnetfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.tar.bz2
netfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.tar.xz
netfs-bfe3b02646e0b34562b28a3771f19b8a265f0856.zip
Improve exception usage around configuration lookups and simplify that code
-rw-r--r--netfs/daemon/Jamfile.jam5
-rw-r--r--netfs/daemon/daemon.cpp7
-rw-r--r--netfs/daemon/daemonConfig.ice7
-rw-r--r--netfs/daemon/daemonConfigImpl.cpp10
-rw-r--r--netfs/daemon/daemonService.cpp11
-rw-r--r--netfs/fuse/Jamfile.jam5
-rw-r--r--netfs/fuse/fuseApp.cpp8
-rw-r--r--netfs/fuse/fuseConfig.ice7
-rw-r--r--netfs/fuse/fuseConfigImpl.cpp10
-rw-r--r--netfs/ice/exceptions.ice5
-rw-r--r--netfs/ice/exceptionsImpl.cpp10
11 files changed, 65 insertions, 20 deletions
diff --git a/netfs/daemon/Jamfile.jam b/netfs/daemon/Jamfile.jam
index c4ae90b..9697e75 100644
--- a/netfs/daemon/Jamfile.jam
+++ b/netfs/daemon/Jamfile.jam
@@ -2,7 +2,10 @@ import package ;
lib netfsd-configuration :
daemonConfig.ice
+ daemonConfigImpl.cpp
:
+ <library>../ice//netfs-api
+ <implicit-dependency>../ice//netfs-api
<library>..//Ice
<library>..//IceUtil
<library>..//pthread
@@ -20,7 +23,7 @@ lib netfsd-configuration :
;
lib netfsd :
- [ glob *.cpp ]
+ [ glob *.cpp : daemonConfigImpl.cpp ]
:
<define>_FILE_OFFSET_BITS=64
<implicit-dependency>../ice//netfs-api
diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp
index d5af905..8ab7bfe 100644
--- a/netfs/daemon/daemon.cpp
+++ b/netfs/daemon/daemon.cpp
@@ -5,6 +5,7 @@
#include <slicer/slicer.h>
#include "modeCheck.h"
#include <sys/stat.h>
+#include <safeMapFind.h>
NetFSDaemon::NetFSDaemon()
{
@@ -55,11 +56,7 @@ NetFSDaemon::LoadConfiguration(const boost::filesystem::path & path)
{
dc = new NetFS::Daemon::RuntimeConfiguration();
dc->CurrentConfiguration = ReadConfiguration(path);
- auto selfItr = dc->CurrentConfiguration->Hosts.find(hostname());
- if (selfItr == dc->CurrentConfiguration->Hosts.end()) {
- throw std::runtime_error("This host is not defined in the configuration.");
- }
- dc->Self = selfItr->second;
+ dc->Self = AdHoc::safeMapLookup<NetFS::Daemon::HostNotConfigured>(dc->CurrentConfiguration->Hosts, hostname());
}
void
diff --git a/netfs/daemon/daemonConfig.ice b/netfs/daemon/daemonConfig.ice
index ac438fb..2ae38e2 100644
--- a/netfs/daemon/daemonConfig.ice
+++ b/netfs/daemon/daemonConfig.ice
@@ -1,3 +1,5 @@
+#include <exceptions.ice>
+
module NetFS {
module Daemon {
local class Host {
@@ -33,5 +35,10 @@ module NetFS {
Configuration CurrentConfiguration;
Host Self;
};
+
+ ["cpp:ice_print"]
+ exception HostNotConfigured extends ConfigError {
+ string hostName;
+ };
};
};
diff --git a/netfs/daemon/daemonConfigImpl.cpp b/netfs/daemon/daemonConfigImpl.cpp
new file mode 100644
index 0000000..48b1d0e
--- /dev/null
+++ b/netfs/daemon/daemonConfigImpl.cpp
@@ -0,0 +1,10 @@
+#include <daemonConfig.h>
+#include <compileTimeFormatter.h>
+
+AdHocFormatter(HostNotConfiguredMsg, "This host [%?] is not defined in the configuration");
+void
+NetFS::Daemon::HostNotConfigured::ice_print(std::ostream & s) const
+{
+ HostNotConfiguredMsg::write(s, hostName);
+}
+
diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp
index be376a0..20082f1 100644
--- a/netfs/daemon/daemonService.cpp
+++ b/netfs/daemon/daemonService.cpp
@@ -1,6 +1,7 @@
#include "daemon.h"
#include "daemonService.h"
#include "daemonVolume.h"
+#include <safeMapFind.h>
ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) :
config(c)
@@ -10,15 +11,11 @@ ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) :
NetFS::VolumePrx
ServiceServer::connect(const std::string & share, const std::string & authtoken, const Ice::Current & ice)
{
- //boost::lock_guard<boost::mutex> lg(lock);
- NetFS::Daemon::ExportMap::iterator e = config->Exports.find(share);
- if (e == config->Exports.end()) {
- throw NetFS::ConfigError();
- }
- if (!e->second->AuthToken.empty() && e->second->AuthToken != authtoken) {
+ auto ex = AdHoc::safeMapLookup<NetFS::ExportNotFound>(config->Exports, share);
+ if (!ex->AuthToken.empty() && ex->AuthToken != authtoken) {
throw NetFS::AuthError();
}
return NetFS::VolumePrx::uncheckedCast(ice.adapter->addFacetWithUUID(
- new VolumeServer(e->second->RootPath, userLookup, groupLookup), "v01"));
+ new VolumeServer(ex->RootPath, userLookup, groupLookup), "v01"));
}
diff --git a/netfs/fuse/Jamfile.jam b/netfs/fuse/Jamfile.jam
index b17ca0b..9df3e89 100644
--- a/netfs/fuse/Jamfile.jam
+++ b/netfs/fuse/Jamfile.jam
@@ -5,8 +5,11 @@ lib Glacier2 : : <name>Glacier2 ;
lib netfs-client-configuration :
fuseConfig.ice
+ fuseConfigImpl.cpp
:
<slicer>yes
+ <library>../ice//netfs-api
+ <implicit-dependency>../ice//netfs-api
<library>..//Ice
<library>..//IceUtil
<library>..//pthread
@@ -21,7 +24,7 @@ lib netfs-client-configuration :
lib netfs-client :
netfs-client-configuration
- [ glob *.cpp : netfs.cpp ]
+ [ glob *.cpp : fuseConfigImpl.cpp netfs.cpp ]
:
<define>_FILE_OFFSET_BITS=64
<implicit-dependency>../ice//netfs-api
diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp
index a998f94..b980af8 100644
--- a/netfs/fuse/fuseApp.cpp
+++ b/netfs/fuse/fuseApp.cpp
@@ -6,6 +6,7 @@
#include <entCache.h>
#include <slicer/slicer.h>
#include <uriParse.h>
+#include <safeMapFind.h>
namespace AdHoc {
template class Cache<struct stat, std::string>;
@@ -82,12 +83,7 @@ NetFS::FuseApp::init(struct fuse_conn_info *)
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);
- }
- return e->second;
+ return AdHoc::safeMapLookup<Client::ResourceNotFound>(ReadConfiguration(configPath)->Resources, resourceName);
}
NetFS::Client::ResourcePtr
diff --git a/netfs/fuse/fuseConfig.ice b/netfs/fuse/fuseConfig.ice
index 91740fc..3e17017 100644
--- a/netfs/fuse/fuseConfig.ice
+++ b/netfs/fuse/fuseConfig.ice
@@ -1,3 +1,5 @@
+#include <exceptions.ice>
+
module NetFS {
module Client {
["slicer:element:endpoint"]
@@ -25,6 +27,11 @@ module NetFS {
["slicer:name:resources"]
ResourceMap Resources;
};
+
+ ["cpp:ice_print"]
+ exception ResourceNotFound extends ConfigError {
+ string resourceName;
+ };
};
};
diff --git a/netfs/fuse/fuseConfigImpl.cpp b/netfs/fuse/fuseConfigImpl.cpp
new file mode 100644
index 0000000..9129bfc
--- /dev/null
+++ b/netfs/fuse/fuseConfigImpl.cpp
@@ -0,0 +1,10 @@
+#include <fuseConfig.h>
+#include <compileTimeFormatter.h>
+
+AdHocFormatter(ResourceNotFoundMsg, "No such resource: %?");
+void
+NetFS::Client::ResourceNotFound::ice_print(std::ostream & s) const
+{
+ ResourceNotFoundMsg::write(s, resourceName);
+}
+
diff --git a/netfs/ice/exceptions.ice b/netfs/ice/exceptions.ice
index 9d5b970..02a42e0 100644
--- a/netfs/ice/exceptions.ice
+++ b/netfs/ice/exceptions.ice
@@ -12,6 +12,11 @@ module NetFS {
exception ConfigError {
};
+
+ ["cpp:ice_print"]
+ exception ExportNotFound extends ConfigError {
+ string exportName;
+ };
};
#endif
diff --git a/netfs/ice/exceptionsImpl.cpp b/netfs/ice/exceptionsImpl.cpp
new file mode 100644
index 0000000..93f5930
--- /dev/null
+++ b/netfs/ice/exceptionsImpl.cpp
@@ -0,0 +1,10 @@
+#include <exceptions.h>
+#include <compileTimeFormatter.h>
+
+AdHocFormatter(ExportNotFoundMsg, "Export [%?] not found on remote host");
+void
+NetFS::ExportNotFound::ice_print(std::ostream & s) const
+{
+ ExportNotFoundMsg::write(s, exportName);
+}
+