[cpp-sp COMMIT] /branches/REL_2/plugins/TransformAttributeResolver.cpp
noreply at shibboleth.net
noreply at shibboleth.net
Fri Apr 6 19:18:49 BST 2012
Author: scantor
Date: Fri Apr 6 19:18:49 2012
New Revision: 3613
URL: http://svn.shibboleth.net/view/cpp-sp?rev=3613&view=rev
Log:
Rework Transform resolver with regex as outer loop
Modified:
branches/REL_2/plugins/TransformAttributeResolver.cpp
Modified: branches/REL_2/plugins/TransformAttributeResolver.cpp
URL: http://svn.shibboleth.net/view/cpp-sp/branches/REL_2/plugins/TransformAttributeResolver.cpp?rev=3613&r1=3612&r2=3613&view=diff
==============================================================================
--- branches/REL_2/plugins/TransformAttributeResolver.cpp (original)
+++ branches/REL_2/plugins/TransformAttributeResolver.cpp Fri Apr 6 19:18:49 2012
@@ -28,6 +28,7 @@
#include <algorithm>
#include <boost/shared_ptr.hpp>
+#include <boost/tuple/tuple.hpp>
#include <shibsp/exceptions.h>
#include <shibsp/SessionCache.h>
#include <shibsp/attribute/SimpleAttribute.h>
@@ -41,6 +42,7 @@
using namespace shibsp;
using namespace xmltooling;
using namespace xercesc;
+using namespace boost;
using namespace std;
namespace shibsp {
@@ -122,21 +124,25 @@
void resolveAttributes(ResolutionContext& ctx) const;
void getAttributeIds(vector<string>& attributes) const {
- if (!m_dest.empty())
- attributes.push_back(m_dest.front());
+ for (vector<regex_t>::const_iterator r = m_regex.begin(); r != m_regex.end(); ++r) {
+ if (!r->get<0>().empty())
+ attributes.push_back(r->get<0>());
+ }
}
private:
Category& m_log;
string m_source;
- vector<string> m_dest;
- vector< pair<boost::shared_ptr<RegularExpression>,const XMLCh*> > m_regex;
+ // dest id, regex to apply, replacement string
+ typedef tuple<string,boost::shared_ptr<RegularExpression>,const XMLCh*> regex_t;
+ vector<regex_t> m_regex;
};
- static const XMLCh dest[] = UNICODE_LITERAL_4(d,e,s,t);
- static const XMLCh match[] = UNICODE_LITERAL_5(m,a,t,c,h);
- static const XMLCh source[] = UNICODE_LITERAL_6(s,o,u,r,c,e);
- static const XMLCh Regex[] = UNICODE_LITERAL_5(R,e,g,e,x);
+ static const XMLCh dest[] = UNICODE_LITERAL_4(d,e,s,t);
+ static const XMLCh match[] = UNICODE_LITERAL_5(m,a,t,c,h);
+ static const XMLCh caseSensitive[] = UNICODE_LITERAL_13(c,a,s,e,S,e,n,s,i,t,i,v,e);
+ static const XMLCh source[] = UNICODE_LITERAL_6(s,o,u,r,c,e);
+ static const XMLCh Regex[] = UNICODE_LITERAL_5(R,e,g,e,x);
AttributeResolver* SHIBSP_DLLLOCAL TransformAttributeResolverFactory(const DOMElement* const & e)
{
@@ -149,8 +155,7 @@
TransformAttributeResolver::TransformAttributeResolver(const DOMElement* e)
: m_log(Category::getInstance(SHIBSP_LOGCAT".AttributeResolver.Transform")),
- m_source(XMLHelper::getAttrString(e, nullptr, source)),
- m_dest(1, XMLHelper::getAttrString(e, nullptr, dest))
+ m_source(XMLHelper::getAttrString(e, nullptr, source))
{
if (m_source.empty())
throw ConfigurationException("Transform AttributeResolver requires source attribute.");
@@ -158,11 +163,14 @@
e = XMLHelper::getFirstChildElement(e, Regex);
while (e) {
if (e->hasChildNodes() && e->hasAttributeNS(nullptr, match)) {
- const XMLCh* repl = e->getTextContent();
+ const XMLCh* repl(e->getTextContent());
+ string destId(XMLHelper::getAttrString(e, nullptr, dest));
+ bool caseflag(XMLHelper::getAttrBool(e, true, caseSensitive));
if (repl && *repl) {
try {
- boost::shared_ptr<RegularExpression> re(new RegularExpression(e->getAttributeNS(nullptr, match)));
- m_regex.push_back(pair<boost::shared_ptr<RegularExpression>,const XMLCh*>(re, repl));
+ static XMLCh options[] = { chLatin_i, chNull };
+ boost::shared_ptr<RegularExpression> re(new RegularExpression(e->getAttributeNS(nullptr, match), (caseflag ? &chNull : options)));
+ m_regex.push_back(make_tuple(destId, re, repl));
}
catch (XMLException& ex) {
auto_ptr_char msg(ex.getMessage());
@@ -185,38 +193,53 @@
if (!tctx.getInputAttributes())
return;
- SimpleAttribute* dest = nullptr;
- auto_ptr<SimpleAttribute> destwrapper;
-
for (vector<Attribute*>::const_iterator a = tctx.getInputAttributes()->begin(); a != tctx.getInputAttributes()->end(); ++a) {
if (m_source != (*a)->getId() || (*a)->valueCount() == 0) {
continue;
}
- else if (m_dest.empty() || m_dest.front().empty()) {
- // Can we transform in-place?
- dest = dynamic_cast<SimpleAttribute*>(*a);
- if (!dest) {
- m_log.warn("can't transform non-simple attribute (%s) in place, skipping it", m_source.c_str());
- continue;
- }
- }
- else if (!destwrapper.get()) {
[... 93 lines stripped ...]
More information about the commits
mailing list