diff --git a/Utils.h b/Utils.h index 440e8d5d..c6119d4f 100644 --- a/Utils.h +++ b/Utils.h @@ -358,7 +358,7 @@ public: // Getters unsigned int GetTTL() { return m_uTTL; } // !Getters -private: +protected: typedef pair value; typedef typename map::iterator iterator; map m_mItems; //!< Map of cached items. The value portion of the map is for the expire time diff --git a/WebModules.cpp b/WebModules.cpp index ebc238f6..fd6cc026 100644 --- a/WebModules.cpp +++ b/WebModules.cpp @@ -12,7 +12,7 @@ #include // Sessions are valid for a day, (24h, ...) -TCacheMap > CWebSock::m_mspSessions(24 * 60 * 60 * 1000); +CWebSessionMap CWebSock::m_mspSessions(24 * 60 * 60 * 1000); CZNCTagHandler::CZNCTagHandler(CWebSock& WebSock) : CTemplateTagHandler(), m_WebSock(WebSock) { } @@ -66,6 +66,17 @@ size_t CWebSession::AddSuccess(const CString& sMessage) { return m_vsSuccessMsgs.size(); } +void CWebSessionMap::FinishUserSessions(const CUser& User) { + iterator it = m_mItems.begin(); + + while (it != m_mItems.end()) { + if (it->second.second->GetUser() == &User) { + m_mItems.erase(it++); + } else { + ++it; + } + } +} void CWebAuth::AcceptedLogin(CUser& User) { if (m_pWebSock) { diff --git a/WebModules.h b/WebModules.h index 3a3044e4..cab73253 100644 --- a/WebModules.h +++ b/WebModules.h @@ -104,6 +104,11 @@ protected: CWebSock* m_pWebSock; }; +class CWebSessionMap : public TCacheMap > { + public: + CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap >(uTTL) {} + void FinishUserSessions(const CUser& User); +}; class CWebSock : public CHTTPSock { public: @@ -148,6 +153,10 @@ public: CString GetCookie(const CString& sKey) const; bool SetCookie(const CString& sKey, const CString& sValue); + static void FinishUserSessions(const CUser& User) { + m_mspSessions.FinishUserSessions(User); + } + private: bool m_bPathsSet; CTemplate m_Template; @@ -158,7 +167,7 @@ private: CString m_sPage; // Gets filled by ResolveModule() CSmartPtr m_spSession; - static TCacheMap > m_mspSessions; + static CWebSessionMap m_mspSessions; }; #endif // !_WEBMODULES_H diff --git a/znc.cpp b/znc.cpp index 4342dea9..384db20e 100644 --- a/znc.cpp +++ b/znc.cpp @@ -208,6 +208,7 @@ bool CZNC::HandleUserDeletion() pUser->DelClients(); pUser->DelModules(); + CWebSock::FinishUserSessions(*pUser); AddBytesRead(pUser->BytesRead()); AddBytesWritten(pUser->BytesWritten()); delete pUser;