[cpp-sp] branch main updated: Centralize property tree boolean conversions.
Scott Cantor
cantor.2 at osu.edu
Thu Dec 5 20:33:42 UTC 2024
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository cpp-sp.
View the commit online:
http://git.shibboleth.net/view/?p=cpp-sp.git;a=commit;h=17dc71b1203e8b69e5bf175832d1925052f5bfe4
The following commit(s) were added to refs/heads/main by this push:
new 17dc71b1 Centralize property tree boolean conversions.
17dc71b1 is described below
commit 17dc71b1203e8b69e5bf175832d1925052f5bfe4
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Dec 5 15:33:35 2024 -0500
Centralize property tree boolean conversions.
---
shibsp/util/BoostPropertySet.cpp | 5 +++--
shibsp/util/Misc.h | 23 +++++++++++++++++++++++
shibsp/util/ReloadableXMLFile.cpp | 19 +------------------
3 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/shibsp/util/BoostPropertySet.cpp b/shibsp/util/BoostPropertySet.cpp
index 50388d97..7c290dff 100644
--- a/shibsp/util/BoostPropertySet.cpp
+++ b/shibsp/util/BoostPropertySet.cpp
@@ -20,6 +20,7 @@
#include "internal.h"
#include "util/BoostPropertySet.h"
+#include "util/Misc.h"
#include <algorithm>
#include <boost/lexical_cast.hpp>
@@ -82,8 +83,8 @@ bool BoostPropertySet::getBool(const char* name, bool defaultValue) const
// Check for a child node with the target name and return its value as a bool.
const boost::optional<const property_tree::ptree&> child = m_pt->get_child_optional(name);
if (child) {
- const string& val = child->data();
- return val == "1" || val == "true";
+ static string_to_bool_translator tr;
+ return child.get().get_value(defaultValue, tr);
}
}
diff --git a/shibsp/util/Misc.h b/shibsp/util/Misc.h
index e38db015..ed03d5b5 100644
--- a/shibsp/util/Misc.h
+++ b/shibsp/util/Misc.h
@@ -19,9 +19,13 @@
*/
#include <shibsp/base.h>
+#include <boost/optional.hpp>
namespace shibsp {
+ /**
+ * Internal utility used for decoding %XX escapes in various places.
+ */
static char x2c(const char* what) {
char digit;
@@ -31,4 +35,23 @@ namespace shibsp {
return(digit);
}
+ /**
+ * Used with the Boost property_tree package to perform string to boolean conversions
+ * in a consistent way.
+ */
+ struct string_to_bool_translator {
+ typedef std::string internal_type;
+ typedef bool external_type;
+
+ boost::optional<bool> get_value(const std::string &s) {
+ if (s == "true" || s == "1") {
+ return boost::make_optional(true);
+ } else if (s == "false" || s == "0") {
+ return boost::make_optional(false);
+ } else {
+ return boost::none;
+ }
+ }
+ };
+
};
\ No newline at end of file
diff --git a/shibsp/util/ReloadableXMLFile.cpp b/shibsp/util/ReloadableXMLFile.cpp
index a9875b11..2f0bc1a9 100644
--- a/shibsp/util/ReloadableXMLFile.cpp
+++ b/shibsp/util/ReloadableXMLFile.cpp
@@ -22,6 +22,7 @@
#include "AgentConfig.h"
#include "logging/Category.h"
+#include "util/Misc.h"
#include "util/PathResolver.h"
#include "util/ReloadableXMLFile.h"
@@ -33,24 +34,6 @@ using namespace boost::property_tree;
using namespace shibsp;
using namespace std;
-namespace {
- // More an experiment than anything but it does encapsulate the conversion...
- struct string_to_bool_translator {
- typedef std::string internal_type;
- typedef bool external_type;
-
- boost::optional<bool> get_value(const string &s) {
- if (s == "true" || s == "1") {
- return boost::make_optional(true);
- } else if (s == "false" || s == "0") {
- return boost::make_optional(false);
- } else {
- return boost::none;
- }
- }
- };
-};
-
const char ReloadableXMLFile::PATH_PROP_NAME[] = "<xmlattr>.path";
const char ReloadableXMLFile::RELOAD_CHANGES_PROP_NAME[] = "<xmlattr>.reloadChanges";
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list