Generate RequestInitiator metadata extension from parentless SessionInitiators.
[shibboleth/cpp-sp.git] / shibsp / handler / impl / ChainingSessionInitiator.cpp
index 38bad77..1b4bfce 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2010 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
 
 using namespace shibsp;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 namespace shibsp {
@@ -49,7 +48,15 @@ namespace shibsp {
             for_each(m_handlers.begin(), m_handlers.end(), xmltooling::cleanup<SessionInitiator>());
         }
         
-        pair<bool,long> run(SPRequest& request, const char* entityID=NULL, bool isHandler=true) const;
+        pair<bool,long> run(SPRequest& request, string& entityID, bool isHandler=true) const;
+
+#ifndef SHIBSP_LITE
+        void generateMetadata(opensaml::saml2md::SPSSODescriptor& role, const char* handlerURL) const {
+            SessionInitiator::generateMetadata(role, handlerURL);
+            for (vector<SessionInitiator*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i)
+                (*i)->generateMetadata(role, handlerURL);
+        }
+#endif
 
     private:
         vector<SessionInitiator*> m_handlers;
@@ -65,7 +72,12 @@ namespace shibsp {
     class SHIBSP_DLLLOCAL SessionInitiatorNodeFilter : public DOMNodeFilter
     {
     public:
-        short acceptNode(const DOMNode* node) const {
+#ifdef SHIBSP_XERCESC_SHORT_ACCEPTNODE
+        short
+#else
+        FilterAction
+#endif
+        acceptNode(const DOMNode* node) const {
             if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,_SessionInitiator))
                 return FILTER_REJECT;
             return FILTER_ACCEPT;
@@ -81,14 +93,14 @@ namespace shibsp {
 };
 
 ChainingSessionInitiator::ChainingSessionInitiator(const DOMElement* e, const char* appId)
-    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator"), &g_SINFilter)
+    : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator.Chaining"), &g_SINFilter)
 {
     SPConfig& conf = SPConfig::getConfig();
 
     // Load up the chain of handlers.
-    e = e ? XMLHelper::getFirstChildElement(e, _SessionInitiator) : NULL;
+    e = e ? XMLHelper::getFirstChildElement(e, _SessionInitiator) : nullptr;
     while (e) {
-        auto_ptr_char type(e->getAttributeNS(NULL,_type));
+        auto_ptr_char type(e->getAttributeNS(nullptr,_type));
         if (type.get() && *(type.get())) {
             try {
                 m_handlers.push_back(conf.SessionInitiatorManager.newPlugin(type.get(),make_pair(e, appId)));
@@ -100,10 +112,15 @@ ChainingSessionInitiator::ChainingSessionInitiator(const DOMElement* e, const ch
         }
         e = XMLHelper::getNextSiblingElement(e, _SessionInitiator);
     }
+
+    m_supportedOptions.insert("isPassive");
 }
 
-pair<bool,long> ChainingSessionInitiator::run(SPRequest& request, const char* entityID, bool isHandler) const
+pair<bool,long> ChainingSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
 {
+    if (!checkCompatibility(request, isHandler))
+        return make_pair(false,0L);
+
     pair<bool,long> ret;
     for (vector<SessionInitiator*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i) {
         ret = (*i)->run(request, entityID, isHandler);