Add Handler feature for config.
[shibboleth/sp.git] / shibsp / AbstractSPRequest.cpp
index 67d00a7..103c2b3 100644 (file)
 #include "ServiceProvider.h"
 #include "SessionCache.h"
 
-#include <log4cpp/Category.hh>
-
 using namespace shibsp;
 using namespace opensaml;
 using namespace xmltooling;
-using namespace log4cpp;
 using namespace std;
 
 AbstractSPRequest::AbstractSPRequest()
@@ -76,12 +73,13 @@ const Application& AbstractSPRequest::getApplication() const
     return *m_app;
 }
 
-Session* AbstractSPRequest::getSession(bool checkTimeout) const
+Session* AbstractSPRequest::getSession(bool checkTimeout, bool ignoreAddress, bool cache) const
 {
     // Only attempt this once.
-    if (m_sessionTried)
+    if (cache && m_sessionTried)
         return m_session;
-    m_sessionTried = true;
+    else if (cache)
+        m_sessionTried = true;
 
     // Get session ID from cookie.
     const Application& app = getApplication();
@@ -92,23 +90,27 @@ Session* AbstractSPRequest::getSession(bool checkTimeout) const
 
     // Need address checking and timeout settings.
     time_t timeout=0;
-    bool consistent=true;
-    const PropertySet* props=app.getPropertySet("Sessions");
-    if (props) {
-        if (checkTimeout) {
-            pair<bool,unsigned int> p=props->getUnsignedInt("timeout");
-            if (p.first)
-                timeout = p.second;
+    if (checkTimeout || !ignoreAddress) {
+        const PropertySet* props=app.getPropertySet("Sessions");
+        if (props) {
+            if (checkTimeout) {
+                pair<bool,unsigned int> p=props->getUnsignedInt("timeout");
+                if (p.first)
+                    timeout = p.second;
+            }
+            pair<bool,bool> pcheck=props->getBool("consistentAddress");
+            if (pcheck.first)
+                ignoreAddress = !pcheck.second;
         }
-        pair<bool,bool> pcheck=props->getBool("consistentAddress");
-        if (pcheck.first)
-            consistent = pcheck.second;
     }
 
     // The cache will either silently pass a session or NULL back, or throw an exception out.
-    return m_session = getServiceProvider().getSessionCache()->find(
-        session_id, app, consistent ? getRemoteAddr().c_str() : NULL, checkTimeout ? &timeout : NULL
+    Session* session = getServiceProvider().getSessionCache()->find(
+        session_id, app, ignoreAddress ? NULL : getRemoteAddr().c_str(), checkTimeout ? &timeout : NULL
         );
+    if (cache)
+        m_session = session;
+    return session;
 }
 
 const char* AbstractSPRequest::getRequestURL() const {
@@ -184,6 +186,9 @@ const char* AbstractSPRequest::getCookie(const char* name) const
 
 const char* AbstractSPRequest::getHandlerURL(const char* resource) const
 {
+    if (!resource)
+        resource = getRequestURL();
+
     if (!m_handlerURL.empty() && resource && !strcmp(getRequestURL(),resource))
         return m_handlerURL.c_str();
         
@@ -269,10 +274,10 @@ const char* AbstractSPRequest::getHandlerURL(const char* resource) const
 void AbstractSPRequest::log(SPLogLevel level, const std::string& msg) const
 {
     reinterpret_cast<Category*>(m_log)->log(
-        (level == SPDebug ? log4cpp::Priority::DEBUG :
-        (level == SPInfo ? log4cpp::Priority::INFO :
-        (level == SPWarn ? log4cpp::Priority::WARN :
-        (level == SPError ? log4cpp::Priority::ERROR : log4cpp::Priority::CRIT)))),
+        (level == SPDebug ? Priority::DEBUG :
+        (level == SPInfo ? Priority::INFO :
+        (level == SPWarn ? Priority::WARN :
+        (level == SPError ? Priority::ERROR : Priority::CRIT)))),
         msg
         );
 }
@@ -280,9 +285,9 @@ void AbstractSPRequest::log(SPLogLevel level, const std::string& msg) const
 bool AbstractSPRequest::isPriorityEnabled(SPLogLevel level) const
 {
     return reinterpret_cast<Category*>(m_log)->isPriorityEnabled(
-        (level == SPDebug ? log4cpp::Priority::DEBUG :
-        (level == SPInfo ? log4cpp::Priority::INFO :
-        (level == SPWarn ? log4cpp::Priority::WARN :
-        (level == SPError ? log4cpp::Priority::ERROR : log4cpp::Priority::CRIT))))
+        (level == SPDebug ? Priority::DEBUG :
+        (level == SPInfo ? Priority::INFO :
+        (level == SPWarn ? Priority::WARN :
+        (level == SPError ? Priority::ERROR : Priority::CRIT))))
         );
 }