[cpp-sp] branch main updated: Strip out TemplateParameters class.
Scott Cantor
cantor.2 at osu.edu
Thu Jan 2 18:03:31 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=6a82e7edab59d1f616aaeca1ee42538fbac43efa
The following commit(s) were added to refs/heads/main by this push:
new 6a82e7ed Strip out TemplateParameters class.
6a82e7ed is described below
commit 6a82e7edab59d1f616aaeca1ee42538fbac43efa
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jan 2 13:03:22 2025 -0500
Strip out TemplateParameters class.
---
shibsp/exceptions.cpp | 88 +++++++++++++++++++++++++
shibsp/util/TemplateParameters.cpp | 127 -------------------------------------
shibsp/util/TemplateParameters.h | 92 ---------------------------
3 files changed, 88 insertions(+), 219 deletions(-)
diff --git a/shibsp/exceptions.cpp b/shibsp/exceptions.cpp
new file mode 100644
index 00000000..e886e35f
--- /dev/null
+++ b/shibsp/exceptions.cpp
@@ -0,0 +1,88 @@
+/**
+ * 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.
+ */
+
+/**
+ * exceptions.cpp
+ *
+ * Exception classes.
+ */
+
+#include "internal.h"
+#include "AgentConfig.h"
+#include "exceptions.h"
+#include "io/HTTPResponse.h"
+#include "util/URLEncoder.h"
+
+using namespace shibsp;
+using namespace std;
+
+agent_exception::agent_exception(const char* msg) : m_status(HTTPResponse::SHIBSP_HTTP_STATUS_ERROR)
+{
+ if (msg)
+ m_msg = msg;
+}
+
+agent_exception::agent_exception(const string& msg) : m_status(HTTPResponse::SHIBSP_HTTP_STATUS_ERROR), m_msg(msg)
+{
+}
+
+agent_exception::~agent_exception() noexcept
+{
+}
+
+const char* agent_exception::what() const noexcept
+{
+ return m_msg.c_str();
+}
+
+int agent_exception::getStatusCode() const noexcept
+{
+ return m_status;
+}
+
+void agent_exception::setStatusCode(int code) noexcept
+{
+ m_status = code;
+}
+
+const unordered_map<string,string>& agent_exception::getProperties() const noexcept
+{
+ return m_props;
+}
+
+void agent_exception::addProperties(const unordered_map<string,string>& props)
+{
+ for (const auto& p : props) {
+ m_props.insert(p);
+ }
+}
+
+void agent_exception::addProperty(const char* name, const char* value)
+{
+ if (name && value) {
+ m_props[name] = value;
+ }
+}
+
+string agent_exception::toQueryString() const
+{
+ string q;
+ const URLEncoder& enc = AgentConfig::getConfig().getURLEncoder();
+ for (const auto& p : m_props) {
+ if (!q.empty())
+ q += '&';
+ q = q + p.first + '=' + enc.encode(p.second.c_str());
+ }
+ return q;
+}
diff --git a/shibsp/util/TemplateParameters.cpp b/shibsp/util/TemplateParameters.cpp
deleted file mode 100644
index 757176d0..00000000
--- a/shibsp/util/TemplateParameters.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * Licensed to the University Corporation for Advanced Internet
- * Development, Inc. (UCAID) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for
- * additional information regarding copyright ownership.
- *
- * UCAID licenses this file to you 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.
- */
-
-/**
- * TemplateParameters.cpp
- *
- * Supplies xmltooling TemplateEngine with additional parameters from a PropertySet.
- */
-
-#include "internal.h"
-#include "SessionCache.h"
-#include "attribute/Attribute.h"
-#include "util/PropertySet.h"
-#include "util/TemplateParameters.h"
-
-#include <ctime>
-#include <xmltooling/XMLToolingConfig.h>
-#include <xmltooling/util/URLEncoder.h>
-
-using namespace shibsp;
-using namespace xmltooling;
-using namespace std;
-
-TemplateParameters::TemplateParameters(const exception* e, const PropertySet* props, const Session* session)
- : m_exception(e), m_toolingException(dynamic_cast<const XMLToolingException*>(e)), m_session(session)
-{
- setPropertySet(props);
-}
-
-TemplateParameters::~TemplateParameters()
-{
-}
-
-void TemplateParameters::setPropertySet(const PropertySet* props)
-{
- m_props = props;
-
- // Create a timestamp.
- time_t now = time(nullptr);
-#if defined(HAVE_CTIME_R_2)
- char timebuf[32];
- m_map["now"] = ctime_r(&now,timebuf);
-#elif defined(HAVE_CTIME_R_3)
- char timebuf[32];
- m_map["now"] = ctime_r(&now,timebuf,sizeof(timebuf));
-#else
- m_map["now"] = ctime(&now);
-#endif
- string& s = m_map["now"];
- s.erase(s.begin() + s.size() - 1);
-}
-
-const XMLToolingException* TemplateParameters::getRichException() const
-{
- return m_toolingException;
-}
-
-const char* TemplateParameters::getParameter(const char* name) const
-{
- if (m_exception) {
- if (!strcmp(name, "errorType"))
- return m_toolingException ? m_toolingException->getClassName() : "std::exception";
- else if (!strcmp(name, "errorText"))
- return m_exception->what();
- }
-
- const char* pch = TemplateEngine::TemplateParameters::getParameter(name);
- if (pch)
- return pch;
-
- if (m_session) {
- if (!strcmp(name, "entityID"))
- return m_session->getEntityID();
-
- const multimap<string,const Attribute*>& attrs = m_session->getIndexedAttributes();
- pair<multimap<string,const Attribute*>::const_iterator, multimap<string,const Attribute*>::const_iterator> walker;
- for (walker = attrs.equal_range(name); walker.first != walker.second; ++walker.first) {
- if (walker.first->second->valueCount() > 0)
- return walker.first->second->getSerializedValues().front().c_str();
- }
- }
-
- if (m_props) {
- pair<bool,const char*> p = m_props->getString(name);
- if (p.first)
- return p.second;
- }
-
- return nullptr;
-}
-
-string TemplateParameters::toQueryString() const
-{
- // Capture local stuff.
- string q;
-
- const URLEncoder* enc = XMLToolingConfig::getConfig().getURLEncoder();
- for (map<string,string>::const_iterator i = m_map.begin(); i != m_map.end(); ++i)
- q = q + '&' + i->first + '=' + enc->encode(i->second.c_str());
-
- // Add in the exception content.
- if (m_exception) {
- q = q + "&errorType=" + enc->encode(getParameter("errorType")) + "&errorText=" + enc->encode(getParameter("errorText"));
- if (m_toolingException)
- q = q + '&' + m_toolingException->toQueryString();
- }
-
- q.erase(0,1);
- return q;
-}
diff --git a/shibsp/util/TemplateParameters.h b/shibsp/util/TemplateParameters.h
deleted file mode 100644
index a93aabe2..00000000
--- a/shibsp/util/TemplateParameters.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * Licensed to the University Corporation for Advanced Internet
- * Development, Inc. (UCAID) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for
- * additional information regarding copyright ownership.
- *
- * UCAID licenses this file to you 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.
- */
-
-/**
- * @file shibsp/util/TemplateParameters.h
- *
- * Supplies xmltooling TemplateEngine with additional parameters.
- */
-
-#ifndef __shibsp_tempparams_h__
-#define __shibsp_tempparams_h__
-
-#include <shibsp/base.h>
-
-#include <xmltooling/exceptions.h>
-#include <xmltooling/util/TemplateEngine.h>
-
-namespace shibsp {
-
- class SHIBSP_API PropertySet;
- class SHIBSP_API Session;
-
- /**
- * Supplies xmltooling TemplateEngine with additional parameters.
- */
- class SHIBSP_API TemplateParameters : public xmltooling::TemplateEngine::TemplateParameters
- {
- public:
- /**
- * Constructor.
- *
- * @param e an exception to supply additional parameters
- * @param props a PropertySet to supply additional parameters
- * @param session an active user session
- */
- TemplateParameters(
- const std::exception* e=nullptr, const PropertySet* props=nullptr, const Session* session=nullptr
- );
-
- virtual ~TemplateParameters();
-
- /**
- * Sets a PropertySet to supply additional parameters.
- *
- * @param props a PropertySet to supply additional parameters
- */
- void setPropertySet(const PropertySet* props);
-
- /**
- * Returns the exception passed to the object, if it contains rich information.
- *
- * @return an exception, or nullptr
- */
- const xmltooling::XMLToolingException* getRichException() const;
-
- const char* getParameter(const char* name) const;
-
- /**
- * Returns a set of query string name/value pairs, URL-encoded,
- * representing all known parameters. If an exception is
- * present, it's type, message, and parameters will be included.
- *
- * @return the query string representation
- */
- std::string toQueryString() const;
-
- private:
- const PropertySet* m_props;
- const std::exception* m_exception;
- const xmltooling::XMLToolingException* m_toolingException;
- const Session* m_session;
- };
-};
-
-#endif /* __shibsp_tempparams_h__ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list