[cpp-sp] branch main updated: Move URLEncoder in from xmltooling.

Scott Cantor cantor.2 at osu.edu
Mon Dec 2 21:32:33 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=ab80790c3d549d8e35af3059f3f824e1d681e0cd

The following commit(s) were added to refs/heads/main by this push:
     new ab80790c Move URLEncoder in from xmltooling.
ab80790c is described below

commit ab80790c3d549d8e35af3059f3f824e1d681e0cd
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Dec 2 16:32:29 2024 -0500

    Move URLEncoder in from xmltooling.
---
 configure.ac                          |  5 ++++-
 shibsp/AgentConfig.h                  |  8 ++++++++
 shibsp/Makefile.am                    |  6 ++++--
 shibsp/ServiceProvider.cpp            | 15 +++++++--------
 shibsp/handler/impl/LogoutHandler.cpp | 12 ++++++------
 shibsp/impl/AgentConfig.cpp           |  7 +++++++
 shibsp/util/BoostPropertySet.cpp      |  2 +-
 shibsp/util/CGIParser.cpp             | 20 ++++++++++----------
 8 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7dc5675b..771c93c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,6 @@ AC_CONFIG_FILES([shibsp.pc])
 
 AC_PROG_CC([gcc gcc3 cc])
 AC_PROG_CXX([g++ g++3 c++ CC])
-AX_CXX_COMPILE_STDCXX([14])
 
 AC_SUBST([AM_CFLAGS])
 AC_SUBST([AM_CXXFLAGS])
@@ -70,6 +69,10 @@ AC_FUNC_STRERROR_R
 AC_CXX_NAMESPACES
 AC_CXX_REQUIRE_STL
 
+AX_CXX_COMPILE_STDCXX([14])
+# Once the code is sanitized, we could include some optional support.
+#AX_CXX_COMPILE_STDCXX([17],,[optional])
+
 # Boost
 BOOST_REQUIRE
 BOOST_BIND
diff --git a/shibsp/AgentConfig.h b/shibsp/AgentConfig.h
index ccb2549f..845987ca 100644
--- a/shibsp/AgentConfig.h
+++ b/shibsp/AgentConfig.h
@@ -32,6 +32,7 @@ namespace shibsp {
     class SHIBSP_API Category;
     class SHIBSP_API LoggingService;
     class SHIBSP_API PathResolver;
+    class SHIBSP_API URLEncoder;
 
 #if defined (_MSC_VER)
     #pragma warning( push )
@@ -87,6 +88,13 @@ namespace shibsp {
          */
         virtual const PathResolver& getPathResolver() const=0;
 
+        /**
+         * Returns a URLEncoder instance.
+         * 
+         * @return URL encoder
+         */
+        virtual const URLEncoder& getURLEncoder() const=0;
+
         /**
          * Returns the global Agent instance.
          * 
diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am
index a2eb0ebd..0724fba1 100644
--- a/shibsp/Makefile.am
+++ b/shibsp/Makefile.am
@@ -74,7 +74,8 @@ utilinclude_HEADERS = \
 	util/PathResolver.h \
 	util/PropertySet.h \
 	util/SPConstants.h \
-	util/TemplateParameters.h
+	util/TemplateParameters.h \
+	util/URLEncoder.h
 
 noinst_HEADERS = \
 	internal.h \
@@ -146,7 +147,8 @@ libshibsp_la_SOURCES = \
 	util/IPRange.cpp \
 	util/PathResolver.cpp \
 	util/SPConstants.cpp \
-	util/TemplateParameters.cpp
+	util/TemplateParameters.cpp \
+	util/URLEncoder.cpp
 
 
 # this is different from the project version
diff --git a/shibsp/ServiceProvider.cpp b/shibsp/ServiceProvider.cpp
index c7e2f37b..735cf2c4 100644
--- a/shibsp/ServiceProvider.cpp
+++ b/shibsp/ServiceProvider.cpp
@@ -36,6 +36,7 @@
 #include "handler/SessionInitiator.h"
 #include "util/PathResolver.h"
 #include "util/TemplateParameters.h"
+#include "util/URLEncoder.h"
 
 #include <fstream>
 #include <sstream>
@@ -43,8 +44,6 @@
 #include <boost/lexical_cast.hpp>
 
 #include <xmltooling/XMLToolingConfig.h>
-#include <xmltooling/util/URLEncoder.h>
-#include <xmltooling/util/XMLHelper.h>
 
 using namespace shibsp;
 using namespace xmltooling;
@@ -175,7 +174,7 @@ namespace shibsp {
         if (enc.first && strcmp(enc.second, "URL"))
             throw ConfigurationException("Unsupported value for 'encoding' content setting ($1).", params(1,enc.second));
 
-        const URLEncoder* encoder = XMLToolingConfig::getConfig().getURLEncoder();
+        const URLEncoder& encoder = AgentConfig::getConfig().getURLEncoder();
 
         // Default delimiter is semicolon but is now configurable.
         pair<bool,const char*> delim = settings.first->getString("attributeValueDelimiter");
@@ -199,7 +198,7 @@ namespace shibsp {
                         header += delim.second;
                     if (enc.first) {
                         // If URL-encoding, any semicolons will get escaped anyway.
-                        header += encoder->encode(v->c_str());
+                        header += encoder.encode(v->c_str());
                     }
                     else {
                         string::size_type pos = v->find(delim.second, string::size_type(0));
@@ -237,7 +236,7 @@ namespace shibsp {
                         header += delim.second;
                     if (enc.first) {
                         // If URL-encoding, any semicolons will get escaped anyway.
-                        header += encoder->encode(v->c_str());
+                        header += encoder.encode(v->c_str());
                     }
                     else {
                         string::size_type pos = v->find(delim.second, string::size_type(0));
@@ -268,7 +267,7 @@ namespace shibsp {
                 const vector<string>& vals = matches.first->second->getSerializedValues();
                 if (!vals.empty()) {
                     if (enc.first)
-                        request.setRemoteUser(encoder->encode(vals.front().c_str()).c_str());
+                        request.setRemoteUser(encoder.encode(vals.front().c_str()).c_str());
                     else
                         request.setRemoteUser(vals.front().c_str());
                     remoteUserSet = true;
@@ -388,7 +387,7 @@ pair<bool,long> ServiceProvider::doAuthentication(SPRequest& request, bool handl
                         loc += '&';
                     else
                         loc += '?';
-                    loc += "return=" + XMLToolingConfig::getConfig().getURLEncoder()->encode(selfurl.c_str());
+                    loc += "return=" + AgentConfig::getConfig().getURLEncoder().encode(selfurl.c_str());
                     return make_pair(true, request.sendRedirect(loc.c_str()));
                 }
             }
@@ -610,7 +609,7 @@ pair<bool,long> ServiceProvider::doExport(SPRequest& request, bool requireSessio
                     count++;
                     *(exportName.rbegin()) = '0' + (count%10);
                     *(++exportName.rbegin()) = '0' + (count/10);
-                    string fullURL = baseURL + XMLToolingConfig::getConfig().getURLEncoder()->encode(*tokenids);
+                    string fullURL = baseURL + AgentConfig::getConfig().getURLEncoder().encode(*tokenids);
                     app->setHeader(request, exportName.c_str(), fullURL.c_str());
                 }
                 app->setHeader(request, "Shib-Assertion-Count", exportName.c_str() + 15);
diff --git a/shibsp/handler/impl/LogoutHandler.cpp b/shibsp/handler/impl/LogoutHandler.cpp
index 33f8d9c2..307f215c 100644
--- a/shibsp/handler/impl/LogoutHandler.cpp
+++ b/shibsp/handler/impl/LogoutHandler.cpp
@@ -34,11 +34,11 @@
 #include "handler/LogoutHandler.h"
 #include "util/TemplateParameters.h"
 #include "util/PathResolver.h"
+#include "util/URLEncoder.h"
 
 #include <fstream>
 #include <boost/lexical_cast.hpp>
 #include <xmltooling/XMLToolingConfig.h>
-#include <xmltooling/util/URLEncoder.h>
 
 using namespace shibsp;
 using namespace xmltooling;
@@ -152,7 +152,7 @@ pair<bool,long> LogoutHandler::notifyFrontChannel(
     if (loc.empty())
         return make_pair(false,0L);
 
-    const URLEncoder* encoder = XMLToolingConfig::getConfig().getURLEncoder();
+    const URLEncoder& encoder = AgentConfig::getConfig().getURLEncoder();
 
     // Start with an "action" telling the application what this is about.
     loc = loc + (strchr(loc.c_str(),'?') ? '&' : '?') + "action=logout";
@@ -167,24 +167,24 @@ pair<bool,long> LogoutHandler::notifyFrontChannel(
 
     // Add return if set.
     if (param)
-        locstr = locstr + "&return=" + encoder->encode(param);
+        locstr = locstr + "&return=" + encoder.encode(param);
 
     // We preserve anything we're instructed to directly.
     if (params) {
         for (map<string,string>::const_iterator p = params->begin(); p!=params->end(); ++p)
-            locstr = locstr + '&' + p->first + '=' + encoder->encode(p->second.c_str());
+            locstr = locstr + '&' + p->first + '=' + encoder.encode(p->second.c_str());
     }
     else {
         for (vector<string>::const_iterator q = m_preserve.begin(); q!=m_preserve.end(); ++q) {
             param = request.getParameter(q->c_str());
             if (param)
-                locstr = locstr + '&' + *q + '=' + encoder->encode(param);
+                locstr = locstr + '&' + *q + '=' + encoder.encode(param);
         }
     }
 
     // Add the notifier's return parameter to the destination location and redirect.
     // This is NOT the same as the return parameter that might be embedded inside it ;-)
-    loc = loc + "&return=" + encoder->encode(locstr.c_str());
+    loc = loc + "&return=" + encoder.encode(locstr.c_str());
     return make_pair(true, response.sendRedirect(loc.c_str()));
 }
 
diff --git a/shibsp/impl/AgentConfig.cpp b/shibsp/impl/AgentConfig.cpp
index 2ac591d2..beab11aa 100644
--- a/shibsp/impl/AgentConfig.cpp
+++ b/shibsp/impl/AgentConfig.cpp
@@ -25,6 +25,7 @@
 #include "AgentConfig.h"
 #include "logging/LoggingService.h"
 #include "util/PathResolver.h"
+#include "util/URLEncoder.h"
 
 #include <ctime>
 #include <stdexcept>
@@ -51,6 +52,11 @@ namespace shibsp {
         const PathResolver& getPathResolver() const {
             return m_pathResolver;
         }
+
+        const URLEncoder& getURLEncoder() const {
+            return m_urlEncoder;
+        }
+
         Agent& getAgent() const;
         LoggingService& getLoggingService() const;
 
@@ -64,6 +70,7 @@ namespace shibsp {
         mutex m_lock;
         ptree m_config;
         PathResolver m_pathResolver;
+        URLEncoder m_urlEncoder;
         unique_ptr<LoggingService> m_logging;
         //unique_ptr<Agent> m_agent;
     };
diff --git a/shibsp/util/BoostPropertySet.cpp b/shibsp/util/BoostPropertySet.cpp
index b0de0aa8..2afcf09f 100644
--- a/shibsp/util/BoostPropertySet.cpp
+++ b/shibsp/util/BoostPropertySet.cpp
@@ -13,7 +13,7 @@
  */
 
 /**
- * BoostPropertySet.cpp
+ * util/BoostPropertySet.cpp
  * 
  * Boost propertytree-based property set implementation.
  */
diff --git a/shibsp/util/CGIParser.cpp b/shibsp/util/CGIParser.cpp
index 8c767226..9b143777 100644
--- a/shibsp/util/CGIParser.cpp
+++ b/shibsp/util/CGIParser.cpp
@@ -25,17 +25,14 @@
  */
 
 #include "internal.h"
+
+#include "AgentConfig.h"
 #include "io/HTTPRequest.h"
 #include "util/CGIParser.h"
-
-#define BOOST_BIND_GLOBAL_PLACEHOLDERS
-#include <boost/bind.hpp>
-#include <xmltooling/XMLToolingConfig.h>
-#include <xmltooling/util/URLEncoder.h>
+#include "util/URLEncoder.h"
 
 using namespace shibsp;
 using namespace xmltooling;
-using namespace boost;
 using namespace std;
 
 namespace {
@@ -110,19 +107,22 @@ CGIParser::CGIParser(const HTTPRequest& request, bool queryOnly)
 
 CGIParser::~CGIParser()
 {
-    static void (*fn)(void*) = &free;
-    for_each(kvp_map.begin(), kvp_map.end(), boost::bind(fn, boost::bind(&multimap<string,char*>::value_type::second, _1)));}
+    for (auto v : kvp_map) {
+        free(v.second);
+    }
+    kvp_map.clear();
+}
 
 void CGIParser::parse(const char* pch)
 {
     size_t cl = pch ? strlen(pch) : 0;
-    const URLEncoder* dec = XMLToolingConfig::getConfig().getURLEncoder();
+    const URLEncoder& dec = AgentConfig::getConfig().getURLEncoder();
     while (cl && pch) {
         char *name;
         char *value;
         value=fmakeword('&', &cl, &pch);
         plustospace(value);
-        dec->decode(value);
+        dec.decode(value);
         name=makeword(value, '=');
         kvp_map.insert(pair<const string,char*>(name, value));
         free(name);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list