+Session* SSCache::find(const Application& app, HTTPRequest& request, const char* client_addr, time_t* timeout)
+{
+ string id = active(app, request);
+ if (id.empty())
+ return nullptr;
+ try {
+ Session* session = find(app, id.c_str(), client_addr, timeout);
+ if (session)
+ return session;
+ HTTPResponse* response = dynamic_cast<HTTPResponse*>(&request);
+ if (response) {
+ if (m_outboundHeader.empty()) {
+ pair<string,const char*> shib_cookie = app.getCookieNameProps("_shibsession_");
+ string exp(shib_cookie.second);
+ exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
+ response->setCookie(shib_cookie.first.c_str(), exp.c_str());
+ }
+ else {
+ response->setResponseHeader(m_outboundHeader.c_str(), nullptr);
+ }
+ }
+ }
+ catch (exception&) {
+ if (m_outboundHeader.empty()) {
+ HTTPResponse* response = dynamic_cast<HTTPResponse*>(&request);
+ if (response) {
+ if (m_outboundHeader.empty()) {
+ pair<string,const char*> shib_cookie = app.getCookieNameProps("_shibsession_");
+ string exp(shib_cookie.second);
+ exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
+ response->setCookie(shib_cookie.first.c_str(), exp.c_str());
+ }
+ else {
+ response->setResponseHeader(m_outboundHeader.c_str(), nullptr);
+ }
+ }
+ }
+ throw;
+ }
+ return nullptr;
+}
+
+void SSCache::remove(const Application& app, const HTTPRequest& request, HTTPResponse* response)
+{
+ if (m_inboundHeader.empty()) {
+ pair<string,const char*> shib_cookie = app.getCookieNameProps("_shibsession_");
+ const char* session_id = request.getCookie(shib_cookie.first.c_str());
+ if (session_id && *session_id) {
+ if (response) {
+ if (m_outboundHeader.empty()) {
+ string exp(shib_cookie.second);
+ exp += "; expires=Mon, 01 Jan 2001 00:00:00 GMT";
+ response->setCookie(shib_cookie.first.c_str(), exp.c_str());
+ }
+ else {
+ response->setResponseHeader(m_outboundHeader.c_str(), nullptr);
+ }
+ }
+ remove(app, session_id);
+ }
+ }
+ else {
+ string session_id = request.getHeader(m_inboundHeader.c_str());
+ if (session_id.empty()) {
+ const char* p = request.getParameter(m_inboundHeader.c_str());
+ if (p)
+ session_id = p;
+ }
+ if (!session_id.empty()) {
+ if (response && !m_outboundHeader.empty())
+ response->setResponseHeader(m_outboundHeader.c_str(), nullptr);
+ remove(app, session_id.c_str());
+ }
+ }
+}
+