WebModules: Switch from CSmartPtr to std::shared_ptr

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2014-09-12 14:55:42 +02:00
parent 67d22c8e42
commit 3953185b04
3 changed files with 24 additions and 24 deletions
+5 -5
View File
@@ -27,7 +27,7 @@ class CWebSock;
class CModule;
class CWebSubPage;
typedef CSmartPtr<CWebSubPage> TWebSubPage;
typedef std::shared_ptr<CWebSubPage> TWebSubPage;
typedef std::vector<TWebSubPage> VWebSubPages;
class CZNCTagHandler : public CTemplateTagHandler {
@@ -102,9 +102,9 @@ private:
VPair m_vParams;
};
class CWebSessionMap : public TCacheMap<CString, CSmartPtr<CWebSession> > {
class CWebSessionMap : public TCacheMap<CString, std::shared_ptr<CWebSession> > {
public:
CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap<CString, CSmartPtr<CWebSession> >(uTTL) {}
CWebSessionMap(unsigned int uTTL = 5000) : TCacheMap<CString, std::shared_ptr<CWebSession> >(uTTL) {}
void FinishUserSessions(const CUser& User);
};
@@ -131,7 +131,7 @@ public:
void PrintErrorPage(const CString& sMessage);
CSmartPtr<CWebSession> GetSession();
std::shared_ptr<CWebSession> GetSession();
virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
static CString GetSkinPath(const CString& sSkinName);
@@ -162,7 +162,7 @@ private:
CString m_sModName;
CString m_sPath;
CString m_sPage;
CSmartPtr<CWebSession> m_spSession;
std::shared_ptr<CWebSession> m_spSession;
static const unsigned int m_uiMaxSessions;
};
+10 -10
View File
@@ -76,10 +76,10 @@ public:
MODCONSTRUCTOR(CWebAdminMod) {
VPair vParams;
vParams.push_back(make_pair("user", ""));
AddSubPage(new CWebSubPage("settings", "Global Settings", CWebSubPage::F_ADMIN));
AddSubPage(new CWebSubPage("edituser", "Your Settings", vParams));
AddSubPage(new CWebSubPage("traffic", "Traffic Info", CWebSubPage::F_ADMIN));
AddSubPage(new CWebSubPage("listusers", "Manage Users", CWebSubPage::F_ADMIN));
AddSubPage(std::make_shared<CWebSubPage>("settings", "Global Settings", CWebSubPage::F_ADMIN));
AddSubPage(std::make_shared<CWebSubPage>("edituser", "Your Settings", vParams));
AddSubPage(std::make_shared<CWebSubPage>("traffic", "Traffic Info", CWebSubPage::F_ADMIN));
AddSubPage(std::make_shared<CWebSubPage>("listusers", "Manage Users", CWebSubPage::F_ADMIN));
}
virtual ~CWebAdminMod() {
@@ -164,7 +164,7 @@ public:
}
CUser* GetNewUser(CWebSock& WebSock, CUser* pUser) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
CString sUsername = WebSock.GetParam("newuser");
if (sUsername.empty()) {
@@ -402,7 +402,7 @@ public:
virtual CString GetWebMenuTitle() { return "webadmin"; }
virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
if (sPageName == "settings") {
// Admin Check
@@ -597,7 +597,7 @@ public:
}
bool ChanPage(CWebSock& WebSock, CTemplate& Tmpl, CIRCNetwork* pNetwork, CChan* pChan = NULL) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
Tmpl.SetFile("add_edit_chan.tmpl");
CUser* pUser = pNetwork->GetUser();
@@ -727,7 +727,7 @@ public:
}
bool NetworkPage(CWebSock& WebSock, CTemplate& Tmpl, CUser* pUser, CIRCNetwork* pNetwork = NULL) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
Tmpl.SetFile("add_edit_network.tmpl");
if (!WebSock.GetParam("submitted").ToUInt()) {
@@ -1073,7 +1073,7 @@ public:
}
bool UserPage(CWebSock& WebSock, CTemplate& Tmpl, CUser* pUser = NULL) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
Tmpl.SetFile("add_edit_user.tmpl");
if (!WebSock.GetParam("submitted").ToUInt()) {
@@ -1380,7 +1380,7 @@ public:
}
bool ListUsersPage(CWebSock& WebSock, CTemplate& Tmpl) {
CSmartPtr<CWebSession> spSession = WebSock.GetSession();
std::shared_ptr<CWebSession> spSession = WebSock.GetSession();
const map<CString,CUser*>& msUsers = CZNC::Get().GetUserMap();
Tmpl["Title"] = "Manage Users";
Tmpl["Action"] = "listusers";
+9 -9
View File
@@ -153,7 +153,7 @@ void CWebSessionMap::FinishUserSessions(const CUser& User) {
void CWebAuth::AcceptedLogin(CUser& User) {
if (m_pWebSock) {
CSmartPtr<CWebSession> spSession = m_pWebSock->GetSession();
std::shared_ptr<CWebSession> spSession = m_pWebSock->GetSession();
spSession->SetUser(&User);
@@ -167,7 +167,7 @@ void CWebAuth::AcceptedLogin(CUser& User) {
void CWebAuth::RefusedLogin(const CString& sReason) {
if (m_pWebSock) {
CSmartPtr<CWebSession> spSession = m_pWebSock->GetSession();
std::shared_ptr<CWebSession> spSession = m_pWebSock->GetSession();
spSession->AddError("Invalid login!");
spSession->SetUser(NULL);
@@ -192,7 +192,7 @@ CWebSock::CWebSock(const CString& sURIPrefix) : CHTTPSock(NULL, sURIPrefix) {
}
CWebSock::~CWebSock() {
if (!m_spAuth.IsNull()) {
if (m_spAuth) {
m_spAuth->Invalidate();
}
@@ -819,13 +819,13 @@ static inline bool compareLastActive(const std::pair<const CString, CWebSession
return first.second->GetLastActive() < second.second->GetLastActive();
}
CSmartPtr<CWebSession> CWebSock::GetSession() {
if (!m_spSession.IsNull()) {
std::shared_ptr<CWebSession> CWebSock::GetSession() {
if (m_spSession) {
return m_spSession;
}
const CString sCookieSessionId = GetRequestCookie("SessionId");
CSmartPtr<CWebSession> *pSession = Sessions.m_mspSessions.GetItem(sCookieSessionId);
std::shared_ptr<CWebSession> *pSession = Sessions.m_mspSessions.GetItem(sCookieSessionId);
if (pSession != NULL) {
// Refresh the timeout
@@ -855,7 +855,7 @@ CSmartPtr<CWebSession> CWebSock::GetSession() {
DEBUG("Auto generated session: [" + sSessionID + "]");
} while (Sessions.m_mspSessions.HasItem(sSessionID));
CSmartPtr<CWebSession> spSession(new CWebSession(sSessionID, GetRemoteIP()));
std::shared_ptr<CWebSession> spSession(new CWebSession(sSessionID, GetRemoteIP()));
Sessions.m_mspSessions.AddItem(spSession->GetId(), spSession);
m_spSession = spSession;
@@ -864,7 +864,7 @@ CSmartPtr<CWebSession> CWebSock::GetSession() {
}
CString CWebSock::GetCSRFCheck() {
CSmartPtr<CWebSession> pSession = GetSession();
std::shared_ptr<CWebSession> pSession = GetSession();
return pSession->GetId().MD5();
}
@@ -889,7 +889,7 @@ Csock* CWebSock::GetSockObj(const CString& sHost, unsigned short uPort) {
}
CString CWebSock::GetSkinName() {
CSmartPtr<CWebSession> spSession = GetSession();
std::shared_ptr<CWebSession> spSession = GetSession();
if (spSession->IsLoggedIn() && !spSession->GetUser()->GetSkinName().empty()) {
return spSession->GetUser()->GetSkinName();