[cpp-sp] branch main updated: Move splitting code into utility functions.
Scott Cantor
cantor.2 at osu.edu
Thu Jan 9 20:19:50 UTC 2025
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=78abbb6285422ea64a479e711d946d1946e4ede0
The following commit(s) were added to refs/heads/main by this push:
new 78abbb62 Move splitting code into utility functions.
78abbb62 is described below
commit 78abbb6285422ea64a479e711d946d1946e4ede0
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jan 9 15:19:43 2025 -0500
Move splitting code into utility functions.
---
shibsp/AbstractSPRequest.cpp | 7 ++--
shibsp/Makefile.am | 3 +-
shibsp/handler/impl/AttributeCheckerHandler.cpp | 9 ++---
shibsp/handler/impl/MetadataGenerator.cpp | 9 +++--
shibsp/handler/impl/SecuredHandler.cpp | 7 +---
shibsp/impl/DefaultAgent.cpp | 10 ++---
shibsp/impl/XMLAccessControl.cpp | 4 +-
shibsp/util/BoostPropertySet.cpp | 3 +-
shibsp/util/Misc.cpp | 49 +++++++++++++++++++++++++
shibsp/util/Misc.h | 9 +++++
10 files changed, 79 insertions(+), 31 deletions(-)
diff --git a/shibsp/AbstractSPRequest.cpp b/shibsp/AbstractSPRequest.cpp
index eed6521b..0b1e343f 100644
--- a/shibsp/AbstractSPRequest.cpp
+++ b/shibsp/AbstractSPRequest.cpp
@@ -26,6 +26,7 @@
#include "logging/Category.h"
#include "session/SessionCache.h"
#include "util/CGIParser.h"
+#include "util/Misc.h"
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
@@ -302,7 +303,7 @@ string AbstractSPRequest::getNotificationURL(bool front, unsigned int index) con
// We have to process the underlying setting each call to this method unfortunately.
const char* rawlocs = getRequestSettings().first->getString(front ? "frontNotifyURLs" : "backNotifyURLs");
vector<string> locs;
- boost::split(locs, rawlocs, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(locs, rawlocs);
if (index >= locs.size())
return string();
@@ -408,9 +409,7 @@ void AbstractSPRequest::limitRedirect(const char* url) const
}
prop = getRequestSettings().first->getString("redirectAllow");
if (prop) {
- string dup(prop);
- boost::trim(dup);
- boost::split(redirectAllow, dup, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(redirectAllow, prop);
}
}
diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am
index bb718e41..3d2e11ee 100644
--- a/shibsp/Makefile.am
+++ b/shibsp/Makefile.am
@@ -110,7 +110,7 @@ libshibsp_la_SOURCES = \
impl/AgentConfig.cpp \
impl/DefaultAgent.cpp \
impl/ChainingAccessControl.cpp \
- impl/XMLAccessControl.cpp \
+ impl/XMLAccessControl.cpp \
impl/XMLRequestMapper.cpp \
io/impl/HTTPRequest.cpp \
io/impl/HTTPResponse.cpp \
@@ -126,6 +126,7 @@ libshibsp_la_SOURCES = \
util/BoostPropertySet.cpp \
util/CGIParser.cpp \
util/IPRange.cpp \
+ util/Misc.cpp \
util/PathResolver.cpp \
util/ReloadableXMLFile.cpp \
util/SPConstants.cpp \
diff --git a/shibsp/handler/impl/AttributeCheckerHandler.cpp b/shibsp/handler/impl/AttributeCheckerHandler.cpp
index acffbbcb..b62b2cd0 100644
--- a/shibsp/handler/impl/AttributeCheckerHandler.cpp
+++ b/shibsp/handler/impl/AttributeCheckerHandler.cpp
@@ -28,10 +28,10 @@
#include "handler/AbstractHandler.h"
#include "logging/Category.h"
#include "session/SessionCache.h"
+#include "util/Misc.h"
#include <memory>
#include <mutex>
-#include <boost/algorithm/string.hpp>
using namespace shibsp;
using namespace boost::property_tree;
@@ -86,10 +86,9 @@ AttributeCheckerHandler::AttributeCheckerHandler(ptree& pt)
m_flushSession = getBool("flushSession", false);
- string attrs(getString("attributes", ""));
- if (!attrs.empty()) {
- boost::trim(attrs);
- boost::split(m_attributes, attrs, boost::is_space(), boost::algorithm::token_compress_on);
+ const char* attrs = getString("attributes", "");
+ if (attrs) {
+ split_to_container(m_attributes, attrs);
if (m_attributes.empty())
throw ConfigurationException("AttributeChecker unable to parse attributes setting.");
}
diff --git a/shibsp/handler/impl/MetadataGenerator.cpp b/shibsp/handler/impl/MetadataGenerator.cpp
index 934060f5..8e2f77bb 100644
--- a/shibsp/handler/impl/MetadataGenerator.cpp
+++ b/shibsp/handler/impl/MetadataGenerator.cpp
@@ -23,11 +23,11 @@
#include "SPRequest.h"
#include "handler/SecuredHandler.h"
#include "logging/Category.h"
+#include "util/Misc.h"
#include <sstream>
#include <string>
#include <vector>
-#include <boost/algorithm/string.hpp>
using namespace shibsp;
using namespace boost::property_tree;
@@ -66,9 +66,10 @@ namespace shibsp {
MetadataGenerator::MetadataGenerator(const ptree& pt)
: SecuredHandler(pt, Category::getInstance(SHIBSP_LOGCAT ".Handler.Metadata"))
{
- string bases(getString("baseURLs", ""));
- boost::trim(bases);
- boost::split(m_bases, bases, boost::is_space(), boost::algorithm::token_compress_on);
+ const char* bases = getString("baseURLs");
+ if (bases) {
+ split_to_container(m_bases, bases);
+ }
}
pair<bool,long> MetadataGenerator::run(SPRequest& request, bool isHandler) const
diff --git a/shibsp/handler/impl/SecuredHandler.cpp b/shibsp/handler/impl/SecuredHandler.cpp
index f2c6e62d..44b74d16 100644
--- a/shibsp/handler/impl/SecuredHandler.cpp
+++ b/shibsp/handler/impl/SecuredHandler.cpp
@@ -28,8 +28,7 @@
#include "SPRequest.h"
#include "handler/SecuredHandler.h"
#include "logging/Category.h"
-
-#include <boost/algorithm/string.hpp>
+#include "util/Misc.h"
#include <sstream>
@@ -42,10 +41,8 @@ SecuredHandler::SecuredHandler(const ptree& pt, Category& log, const char* aclPr
{
const char* acl = getString(aclProperty, defaultACL);
if (acl) {
- string aclbuf(acl);
- boost::trim(aclbuf);
vector<string> aclarray;
- boost::split(aclarray, aclbuf, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(aclarray, acl);
for_each(aclarray.begin(), aclarray.end(), [this](const string& s){parseACL(s);});
if (m_acl.empty()) {
diff --git a/shibsp/impl/DefaultAgent.cpp b/shibsp/impl/DefaultAgent.cpp
index 2b2c9745..952a417e 100644
--- a/shibsp/impl/DefaultAgent.cpp
+++ b/shibsp/impl/DefaultAgent.cpp
@@ -31,8 +31,8 @@
#include "session/SessionCache.h"
#include "util/BoostPropertySet.h"
#include "util/SPConstants.h"
+#include "util/Misc.h"
-#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
using namespace shibsp;
@@ -118,16 +118,12 @@ void DefaultAgent::init()
const char* prop = getString("allowedSchemes", "https http");
if (prop) {
HTTPResponse::getAllowedSchemes().clear();
- string schemes(prop);
- boost::trim(schemes);
- boost::split(HTTPResponse::getAllowedSchemes(), schemes, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(HTTPResponse::getAllowedSchemes(), prop);
}
prop = getString("extraAuthTypes");
if (prop) {
- string types(prop);
- boost::trim(types);
- boost::split(m_authTypes, types, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(m_authTypes, prop);
m_authTypes.insert("shibboleth");
}
diff --git a/shibsp/impl/XMLAccessControl.cpp b/shibsp/impl/XMLAccessControl.cpp
index ae830c9b..380b1cc2 100644
--- a/shibsp/impl/XMLAccessControl.cpp
+++ b/shibsp/impl/XMLAccessControl.cpp
@@ -33,7 +33,6 @@
#include <algorithm>
#include <memory>
#include <set>
-#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
#ifdef SHIBSP_USE_BOOST_REGEX
@@ -157,8 +156,7 @@ Rule::Rule(const ptree& pt) : m_alias(pt.get(REQUIRE_PROP_PATH, ""))
return;
}
- boost::trim(vals);
- split(m_vals, vals, boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(m_vals, vals.c_str());
if (m_vals.empty())
throw ConfigurationException("Rule did not contain any usable values.");
}
diff --git a/shibsp/util/BoostPropertySet.cpp b/shibsp/util/BoostPropertySet.cpp
index f0e5d922..576c0471 100644
--- a/shibsp/util/BoostPropertySet.cpp
+++ b/shibsp/util/BoostPropertySet.cpp
@@ -24,7 +24,6 @@
#include <algorithm>
#include <boost/lexical_cast.hpp>
-#include <boost/algorithm/string.hpp>
#include <boost/property_tree/ptree.hpp>
using namespace shibsp;
@@ -72,7 +71,7 @@ void BoostPropertySet::load(const ptree& pt, const char* unsetter)
if (unsetter) {
const boost::optional<string> val = m_pt->get_optional<string>(unsetter);
if (val) {
- boost::split(m_unset, val.get(), boost::is_space(), boost::algorithm::token_compress_on);
+ split_to_container(m_unset, val.get().c_str());
}
}
}
diff --git a/shibsp/util/Misc.cpp b/shibsp/util/Misc.cpp
new file mode 100644
index 00000000..9afd0f06
--- /dev/null
+++ b/shibsp/util/Misc.cpp
@@ -0,0 +1,49 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * util/Misc.cpp
+ *
+ * Utility function implementations.
+ */
+
+#include "internal.h"
+#include "util/Misc.h"
+
+#include <set>
+#include <vector>
+#include <boost/algorithm/string.hpp>
+
+using namespace shibsp;
+using namespace std;
+
+vector<string>::size_type split_to_container(vector<string>& container, const char* s)
+{
+ if (s) {
+ string dup(s);
+ boost::trim(dup);
+ boost::split(container, dup, boost::is_space(), boost::token_compress_on);
+ }
+ return container.size();
+}
+
+set<string>::size_type split_to_container(set<string>& container, const char* s)
+{
+ if (s) {
+ string dup(s);
+ boost::trim(dup);
+ boost::split(container, dup, boost::is_space(), boost::token_compress_on);
+ }
+ return container.size();
+}
diff --git a/shibsp/util/Misc.h b/shibsp/util/Misc.h
index ed03d5b5..5fd18b00 100644
--- a/shibsp/util/Misc.h
+++ b/shibsp/util/Misc.h
@@ -19,6 +19,10 @@
*/
#include <shibsp/base.h>
+
+#include <set>
+#include <string>
+#include <vector>
#include <boost/optional.hpp>
namespace shibsp {
@@ -54,4 +58,9 @@ namespace shibsp {
}
};
+ /**
+ * Splitter functions that trim the input and split on whitespace into a container.
+ */
+ static std::vector<std::string>::size_type split_to_container(std::vector<std::string>& container, const char* s);
+ static std::set<std::string>::size_type split_to_container(std::set<std::string>& container, const char* s);
};
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list