diff --git a/WebModules.cpp b/WebModules.cpp index 4358eb5f..aec6f25e 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -11,7 +11,8 @@ #include "znc.h" #include -map > CWebSock::m_mspSessions; +// Sessions are valid for a day, (24h, ...) +TCacheMap > CWebSock::m_mspSessions(24 * 60 * 60 * 1000); CZNCTagHandler::CZNCTagHandler(CWebSock& WebSock) : CTemplateTagHandler(), m_WebSock(WebSock) { } @@ -601,11 +602,13 @@ CSmartPtr CWebSock::GetSession() { return m_spSession; } - map >::const_iterator it = m_mspSessions.find(GetCookie("SessionId")); + CSmartPtr *pSession = m_mspSessions.GetItem(GetCookie("SessionId")); - if (it != m_mspSessions.end()) { - DEBUG("Found existing session from cookie: [" + GetCookie("SessionId") + "] IsLoggedIn(" + CString(it->second->IsLoggedIn() ? "true" : "false") + ")"); - return it->second; + if (pSession != NULL) { + // Refresh the timeout + m_mspSessions.AddItem((*pSession)->GetId(), *pSession); + DEBUG("Found existing session from cookie: [" + GetCookie("SessionId") + "] IsLoggedIn(" + CString((*pSession)->IsLoggedIn() ? "true" : "false") + ")"); + return *pSession; } CString sSessionID; @@ -617,10 +620,10 @@ CSmartPtr CWebSock::GetSession() { sSessionID = sSessionID.SHA256(); DEBUG("Auto generated session: [" + sSessionID + "]"); - } while (m_mspSessions.find(sSessionID) != m_mspSessions.end()); + } while (m_mspSessions.HasItem(sSessionID)); CSmartPtr spSession(new CWebSession(sSessionID)); - m_mspSessions.insert(make_pair(spSession->GetId(), spSession)); + m_mspSessions.AddItem(spSession->GetId(), spSession); return spSession; } diff --git a/WebModules.h b/WebModules.h index d3065a05..b5929b40 100644 --- a/WebModules.h +++ b/WebModules.h @@ -157,7 +157,7 @@ private: CString m_sPage; // Gets filled by ResolveModule() CSmartPtr m_spSession; - static map > m_mspSessions; + static TCacheMap > m_mspSessions; }; #endif // !_WEBMODULES_H