mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Merge commit 'refs/pull/665/head' of github.com:znc/znc
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
|
||||
#include <znc/zncconfig.h>
|
||||
#include <znc/Socket.h>
|
||||
#include <znc/Utils.h>
|
||||
#include <znc/main.h>
|
||||
#include <memory>
|
||||
|
||||
// Forward Declarations
|
||||
class CZNC;
|
||||
@@ -172,7 +172,7 @@ protected:
|
||||
CString m_sPass;
|
||||
CString m_sUser;
|
||||
CString m_sNetwork;
|
||||
CSmartPtr<CAuthBase> m_spAuth;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
SCString m_ssAcceptedCaps;
|
||||
};
|
||||
|
||||
|
||||
@@ -1013,7 +1013,7 @@ public:
|
||||
* @param Auth The necessary authentication info for this login attempt.
|
||||
* @return See CModule::EModRet.
|
||||
*/
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth);
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth);
|
||||
/** Called after a client login was rejected.
|
||||
* @param sUsername The username that tried to log in.
|
||||
* @param sRemoteIP The IP address from which the client tried to login.
|
||||
@@ -1223,7 +1223,7 @@ public:
|
||||
bool OnAddUser(CUser& User, CString& sErrorRet);
|
||||
bool OnDeleteUser(CUser& User);
|
||||
bool OnClientConnect(CZNCSock* pSock, const CString& sHost, unsigned short uPort);
|
||||
bool OnLoginAttempt(CSmartPtr<CAuthBase> Auth);
|
||||
bool OnLoginAttempt(std::shared_ptr<CAuthBase> Auth);
|
||||
bool OnFailedLogin(const CString& sUsername, const CString& sRemoteIP);
|
||||
bool OnUnknownUserRaw(CClient* pClient, CString& sLine);
|
||||
bool OnClientCapLs(CClient* pClient, SCString& ssCaps);
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
#define _TEMPLATE_H
|
||||
|
||||
#include <znc/zncconfig.h>
|
||||
#include <znc/Utils.h>
|
||||
#include <znc/ZNCString.h>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
class CTemplate;
|
||||
|
||||
@@ -124,7 +125,7 @@ public:
|
||||
Init();
|
||||
}
|
||||
|
||||
CTemplate(const CSmartPtr<CTemplateOptions>& Options, CTemplate* pParent = NULL) : MCString(), m_spOptions(Options) {
|
||||
CTemplate(const std::shared_ptr<CTemplateOptions>& Options, CTemplate* pParent = NULL) : MCString(), m_spOptions(Options) {
|
||||
Init();
|
||||
m_pParent = pParent;
|
||||
}
|
||||
@@ -132,11 +133,11 @@ public:
|
||||
virtual ~CTemplate();
|
||||
|
||||
//! Class for implementing custom tags in subclasses
|
||||
void AddTagHandler(CSmartPtr<CTemplateTagHandler> spTagHandler) {
|
||||
void AddTagHandler(std::shared_ptr<CTemplateTagHandler> spTagHandler) {
|
||||
m_vspTagHandlers.push_back(spTagHandler);
|
||||
}
|
||||
|
||||
std::vector<CSmartPtr<CTemplateTagHandler> >& GetTagHandlers() {
|
||||
std::vector<std::shared_ptr<CTemplateTagHandler> >& GetTagHandlers() {
|
||||
if (m_pParent) {
|
||||
return m_pParent->GetTagHandlers();
|
||||
}
|
||||
@@ -182,8 +183,8 @@ private:
|
||||
std::list<std::pair<CString, bool> > m_lsbPaths;
|
||||
std::map<CString, std::vector<CTemplate*> > m_mvLoops;
|
||||
std::vector<CTemplateLoopContext*> m_vLoopContexts;
|
||||
CSmartPtr<CTemplateOptions> m_spOptions;
|
||||
std::vector<CSmartPtr<CTemplateTagHandler> > m_vspTagHandlers;
|
||||
std::shared_ptr<CTemplateOptions> m_spOptions;
|
||||
std::vector<std::shared_ptr<CTemplateTagHandler> > m_vspTagHandlers;
|
||||
};
|
||||
|
||||
#endif // !_TEMPLATE_H
|
||||
|
||||
@@ -354,155 +354,4 @@ protected:
|
||||
unsigned int m_uTTL; //!< Default time-to-live duration
|
||||
};
|
||||
|
||||
/**
|
||||
* @class CSmartPtr
|
||||
* @author prozac <prozac@rottenboy.com>
|
||||
* @brief This is a standard reference counting pointer. Be careful not to have two of these point to the same raw pointer or one will be deleted while the other still thinks it is valid.
|
||||
*/
|
||||
template<typename T>
|
||||
class CSmartPtr {
|
||||
public:
|
||||
/**
|
||||
* @brief Standard constructor, points to nothing
|
||||
*/
|
||||
CSmartPtr() {
|
||||
m_pType = NULL;
|
||||
m_puCount = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attach to an existing raw pointer, be CAREFUL not to have more than one CSmartPtr attach to the same raw pointer or bad things will happen
|
||||
* @param pRawPtr The raw pointer to attach to
|
||||
*/
|
||||
CSmartPtr(T* pRawPtr) {
|
||||
m_pType = NULL;
|
||||
m_puCount = NULL;
|
||||
|
||||
Attach(pRawPtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy constructor, will copy the raw pointer and counter locations and increment the reference counter
|
||||
* @param CopyFrom A reference of another CSmartPtr to copy from
|
||||
*/
|
||||
CSmartPtr(const CSmartPtr<T>& CopyFrom) {
|
||||
m_pType = NULL;
|
||||
m_puCount = NULL;
|
||||
|
||||
*this = CopyFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor will Release() the raw pointer and delete it if this was the last reference
|
||||
*/
|
||||
~CSmartPtr() {
|
||||
Release();
|
||||
}
|
||||
|
||||
// Overloaded operators
|
||||
T& operator *() const { assert(m_pType); return *m_pType; }
|
||||
T* operator ->() const { assert(m_pType); return m_pType; }
|
||||
|
||||
/**
|
||||
* @brief Attach() to a raw pointer
|
||||
* @param pRawPtr The raw pointer to keep track of, ***WARNING*** Do _NOT_ allow more than one CSmartPtr keep track of the same raw pointer
|
||||
* @return Reference to self
|
||||
*/
|
||||
CSmartPtr<T>& operator =(T* pRawPtr) { Attach(pRawPtr); return *this; }
|
||||
|
||||
/**
|
||||
* @brief Copies an existing CSmartPtr adding another reference to the counter
|
||||
* @param CopyFrom A reference to another CSmartPtr to be copied
|
||||
* @return Reference to self
|
||||
*/
|
||||
CSmartPtr<T>& operator =(const CSmartPtr<T>& CopyFrom) {
|
||||
if (&CopyFrom != this) { // Check for assignment to self
|
||||
Release(); // Release the current pointer
|
||||
|
||||
if (CopyFrom.IsNull()) { // If the source raw pointer is null
|
||||
return *this; // Then just bail out
|
||||
}
|
||||
|
||||
m_pType = CopyFrom.m_pType; // Make our pointers reference the same raw pointer and counter
|
||||
m_puCount = CopyFrom.m_puCount;
|
||||
|
||||
assert(m_puCount); // We now point to something valid, so increment the counter
|
||||
(*m_puCount)++;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
// !Overloaded operators
|
||||
|
||||
/**
|
||||
* @brief Implicit type conversion to bool for things like if (!ptr) {} and if (ptr) {}
|
||||
* @return @see IsNull()
|
||||
*/
|
||||
operator bool() const {
|
||||
return !IsNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check to see if the underlying raw pointer is null
|
||||
* @return Whether or not underlying raw pointer is null
|
||||
*/
|
||||
bool IsNull() const {
|
||||
return (m_pType == NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attach to a given raw pointer, it will Release() the current raw pointer and assign the new one
|
||||
* @param pRawPtr The raw pointer to keep track of, ***WARNING*** Do _NOT_ allow more than one CSmartPtr keep track of the same raw pointer
|
||||
* @return Reference to self
|
||||
*/
|
||||
CSmartPtr<T>& Attach(T* pRawPtr) {
|
||||
if (pRawPtr != m_pType) { // Check for assignment to self
|
||||
Release(); // Release the current pointer
|
||||
m_pType = pRawPtr; // Point to the passed raw pointer
|
||||
|
||||
if (m_pType) { // If the passed pointer was valid
|
||||
m_puCount = new unsigned int(1); // Create a new counter starting at 1 (us)
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Releases the underlying raw pointer and cleans up if we were the last reference to said pointer
|
||||
*/
|
||||
void Release() {
|
||||
if (m_pType) { // Only release if there is something to be released
|
||||
assert(m_puCount);
|
||||
(*m_puCount)--; // Decrement our counter
|
||||
|
||||
if (!*m_puCount) { // If we were the last reference to this pointer, then clean up
|
||||
delete m_puCount;
|
||||
delete m_pType;
|
||||
}
|
||||
|
||||
m_pType = NULL; // Get rid of our references
|
||||
m_puCount = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Getters
|
||||
T* GetPtr() const { return m_pType; }
|
||||
unsigned int GetCount() const { return (m_puCount) ? *m_puCount : 0; }
|
||||
// !Getters
|
||||
private:
|
||||
T* m_pType; //!< Raw pointer to the class being referenced
|
||||
unsigned int* m_puCount; //!< Counter of how many CSmartPtr's are referencing the same raw pointer
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
bool operator ==(T* lhs, const CSmartPtr<T>& rhs) { return (lhs == rhs.GetPtr()); }
|
||||
|
||||
template<typename T>
|
||||
bool operator ==(const CSmartPtr<T>& lhs, T* rhs) { return (lhs.GetPtr() == rhs); }
|
||||
|
||||
template<typename T>
|
||||
bool operator ==(const CSmartPtr<T>& lhs, const CSmartPtr<T>& rhs) { return (lhs.GetPtr() == rhs.GetPtr()); }
|
||||
|
||||
#endif // !_UTILS_H
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -157,11 +157,11 @@ private:
|
||||
|
||||
bool m_bPathsSet;
|
||||
CTemplate m_Template;
|
||||
CSmartPtr<CAuthBase> m_spAuth;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -89,8 +89,7 @@ public:
|
||||
|
||||
// Authenticate a user.
|
||||
// The result is passed back via callbacks to CAuthBase.
|
||||
// CSmartPtr handles freeing this pointer!
|
||||
void AuthUser(CSmartPtr<CAuthBase> AuthClass);
|
||||
void AuthUser(std::shared_ptr<CAuthBase> AuthClass);
|
||||
|
||||
// Setters
|
||||
void SetConfigState(enum ConfigState e) { m_eConfigState = e; }
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
if (IsBlocked(Auth->GetUsername())) {
|
||||
Auth->RefuseLogin(MESSAGE);
|
||||
return HALT;
|
||||
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
return pair.second;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
const CString sUser = Auth->GetUsername();
|
||||
Csock *pSock = Auth->GetSocket();
|
||||
CUser *pUser = CZNC::Get().FindUser(sUser);
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
const CString& sUsername = Auth->GetUsername();
|
||||
const CString& sPassword = Auth->GetPassword();
|
||||
CUser *pUser(CZNC::Get().FindUser(sUsername));
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
Add(sRemoteIP, 1);
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
// e.g. webadmin ends up here
|
||||
const CString& sRemoteIP = Auth->GetRemoteIP();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class CIMAPAuthMod;
|
||||
|
||||
class CIMAPSock : public CSocket {
|
||||
public:
|
||||
CIMAPSock(CIMAPAuthMod* pModule, CSmartPtr<CAuthBase> Auth)
|
||||
CIMAPSock(CIMAPAuthMod* pModule, std::shared_ptr<CAuthBase> Auth)
|
||||
: CSocket((CModule*) pModule), m_spAuth(Auth) {
|
||||
m_pIMAPMod = pModule;
|
||||
m_bSentReply = false;
|
||||
@@ -39,10 +39,10 @@ public:
|
||||
virtual void ReadLine(const CString& sLine);
|
||||
private:
|
||||
protected:
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
CSmartPtr<CAuthBase> m_spAuth;
|
||||
CIMAPAuthMod* m_pIMAPMod;
|
||||
bool m_bSentLogin;
|
||||
bool m_bSentReply;
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
};
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
CUser* pUser = CZNC::Get().FindUser(Auth->GetUsername());
|
||||
|
||||
if (!pUser) { // @todo Will want to do some sort of && !m_bAllowCreate in the future
|
||||
|
||||
@@ -242,7 +242,7 @@ typedef std::vector<std::pair<CString, CString> > VPair;
|
||||
|
||||
%inline %{
|
||||
TWebSubPage _CreateWebSubPage(const CString& sName, const CString& sTitle, const VPair& vParams, unsigned int uFlags) {
|
||||
return new CWebSubPage(sName, sTitle, vParams, uFlags);
|
||||
return std::make_shared<CWebSubPage>(sName, sTitle, vParams, uFlags);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ while (<$in>) {
|
||||
say $out "Py_BuildValue(\"l\", (long int)$a->{var});";
|
||||
}
|
||||
}
|
||||
when (/^CSmartPtr/) {
|
||||
when (/^std::shared_ptr/) {
|
||||
say $out "SWIG_NewInstanceObj(new $a->{type}($a->{var}), SWIG_TypeQuery(\"$a->{type}*\"), SWIG_POINTER_OWN);";
|
||||
}
|
||||
when (/\*$/) {
|
||||
|
||||
@@ -78,4 +78,4 @@ EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg)
|
||||
EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, CString& sRetMsg)
|
||||
void OnGetAvailableMods(std::set<CModInfo>& ssMods, CModInfo::EModuleType eType)
|
||||
void OnClientCapLs(CClient* pClient, SCString& ssCaps)
|
||||
EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth)
|
||||
EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth)
|
||||
|
||||
@@ -58,6 +58,7 @@ using std::allocator;
|
||||
%include <std_list.i>
|
||||
%include <std_set.i>
|
||||
%include <std_deque.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%include "modpython/cstring.i"
|
||||
%template(_stringlist) std::list<CString>;
|
||||
@@ -129,8 +130,8 @@ class MCString : public std::map<CString, CString> {};
|
||||
%include "../include/znc/defines.h"
|
||||
%include "../include/znc/Utils.h"
|
||||
%include "../include/znc/Threads.h"
|
||||
%template(PAuthBase) CSmartPtr<CAuthBase>;
|
||||
%template(WebSession) CSmartPtr<CWebSession>;
|
||||
%template(PAuthBase) std::shared_ptr<CAuthBase>;
|
||||
%template(WebSession) std::shared_ptr<CWebSession>;
|
||||
%include "../include/znc/Config.h"
|
||||
%include "../include/znc/Csocket.h"
|
||||
%template(ZNCSocketManager) TSocketManager<CZNCSock>;
|
||||
@@ -308,7 +309,7 @@ typedef std::vector<std::pair<CString, CString> > VPair;
|
||||
|
||||
%inline %{
|
||||
TWebSubPage CreateWebSubPage_(const CString& sName, const CString& sTitle, const VPair& vParams, unsigned int uFlags) {
|
||||
return new CWebSubPage(sName, sTitle, vParams, uFlags);
|
||||
return std::make_shared<CWebSubPage>(sName, sTitle, vParams, uFlags);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
bool& bSuccess, CString& sRetMsg);
|
||||
virtual void OnGetAvailableMods(std::set<CModInfo>& ssMods, CModInfo::EModuleType eType);
|
||||
virtual void OnClientCapLs(CClient* pClient, SCString& ssCaps);
|
||||
virtual EModRet OnLoginAttempt(CSmartPtr<CAuthBase> Auth);
|
||||
virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth);
|
||||
};
|
||||
|
||||
static inline CPyModule* AsPyModule(CModule* p) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -733,7 +733,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()) {
|
||||
@@ -1092,7 +1092,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()) {
|
||||
@@ -1399,7 +1399,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";
|
||||
|
||||
@@ -67,7 +67,7 @@ using std::vector;
|
||||
}
|
||||
|
||||
CClient::~CClient() {
|
||||
if (!m_spAuth.IsNull()) {
|
||||
if (m_spAuth) {
|
||||
CClientAuth* pAuth = (CClientAuth*) &(*m_spAuth);
|
||||
pAuth->Invalidate();
|
||||
}
|
||||
@@ -631,7 +631,7 @@ void CClient::AuthUser() {
|
||||
if (!m_bGotNick || !m_bGotUser || !m_bGotPass || m_bInCap || IsAttached())
|
||||
return;
|
||||
|
||||
m_spAuth = new CClientAuth(this, m_sUser, m_sPass);
|
||||
m_spAuth = std::make_shared<CClientAuth>(this, m_sUser, m_sPass);
|
||||
|
||||
CZNC::Get().AuthUser(m_spAuth);
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ bool CModule::PutModNotice(const CString& sLine) {
|
||||
CModule::EModRet CModule::OnAddUser(CUser& User, CString& sErrorRet) { return CONTINUE; }
|
||||
CModule::EModRet CModule::OnDeleteUser(CUser& User) { return CONTINUE; }
|
||||
void CModule::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned short uPort) {}
|
||||
CModule::EModRet CModule::OnLoginAttempt(CSmartPtr<CAuthBase> Auth) { return CONTINUE; }
|
||||
CModule::EModRet CModule::OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) { return CONTINUE; }
|
||||
void CModule::OnFailedLogin(const CString& sUsername, const CString& sRemoteIP) {}
|
||||
CModule::EModRet CModule::OnUnknownUserRaw(CClient* pClient, CString& sLine) { return CONTINUE; }
|
||||
void CModule::OnClientCapLs(CClient* pClient, SCString& ssCaps) {}
|
||||
@@ -920,7 +920,7 @@ bool CModules::OnClientConnect(CZNCSock* pClient, const CString& sHost, unsigned
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CModules::OnLoginAttempt(CSmartPtr<CAuthBase> Auth) {
|
||||
bool CModules::OnLoginAttempt(std::shared_ptr<CAuthBase> Auth) {
|
||||
MODHALTCHK(OnLoginAttempt(Auth));
|
||||
}
|
||||
|
||||
|
||||
@@ -581,14 +581,14 @@ bool CTemplate::Print(const CString& sFileName, ostream& oOut) {
|
||||
}
|
||||
} else if (bNotFound) {
|
||||
// Unknown tag that isn't being skipped...
|
||||
vector<CSmartPtr<CTemplateTagHandler> >& vspTagHandlers = GetTagHandlers();
|
||||
vector<std::shared_ptr<CTemplateTagHandler> >& vspTagHandlers = GetTagHandlers();
|
||||
|
||||
if (!vspTagHandlers.empty()) { // @todo this should go up to the top to grab handlers
|
||||
CTemplate* pTmpl = GetCurTemplate();
|
||||
CString sCustomOutput;
|
||||
|
||||
for (unsigned int j = 0; j < vspTagHandlers.size(); j++) {
|
||||
CSmartPtr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
std::shared_ptr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
|
||||
if (spTagHandler->HandleTag(*pTmpl, sAction, sArgs, sCustomOutput)) {
|
||||
sOutput += sCustomOutput;
|
||||
@@ -826,14 +826,14 @@ CString CTemplate::GetValue(const CString& sArgs, bool bFromIf) {
|
||||
sRet = (it != end()) ? it->second : "";
|
||||
}
|
||||
|
||||
vector<CSmartPtr<CTemplateTagHandler> >& vspTagHandlers = GetTagHandlers();
|
||||
vector<std::shared_ptr<CTemplateTagHandler> >& vspTagHandlers = GetTagHandlers();
|
||||
|
||||
if (!vspTagHandlers.empty()) { // @todo this should go up to the top to grab handlers
|
||||
CTemplate* pTmpl = GetCurTemplate();
|
||||
|
||||
if (sRet.empty()) {
|
||||
for (unsigned int j = 0; j < vspTagHandlers.size(); j++) {
|
||||
CSmartPtr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
std::shared_ptr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
CString sCustomOutput;
|
||||
|
||||
if (!bFromIf && spTagHandler->HandleVar(*pTmpl, sArgs.Token(0), sArgs.Token(1, true), sCustomOutput)) {
|
||||
@@ -847,7 +847,7 @@ CString CTemplate::GetValue(const CString& sArgs, bool bFromIf) {
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < vspTagHandlers.size(); j++) {
|
||||
CSmartPtr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
std::shared_ptr<CTemplateTagHandler> spTagHandler = vspTagHandlers[j];
|
||||
|
||||
if (spTagHandler->HandleValue(*pTmpl, sRet, msArgs)) {
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
@@ -188,11 +188,11 @@ void CWebAuth::Invalidate() {
|
||||
CWebSock::CWebSock(const CString& sURIPrefix) : CHTTPSock(NULL, sURIPrefix) {
|
||||
m_bPathsSet = false;
|
||||
|
||||
m_Template.AddTagHandler(new CZNCTagHandler(*this));
|
||||
m_Template.AddTagHandler(std::make_shared<CZNCTagHandler>(*this));
|
||||
}
|
||||
|
||||
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,13 +864,13 @@ CSmartPtr<CWebSession> CWebSock::GetSession() {
|
||||
}
|
||||
|
||||
CString CWebSock::GetCSRFCheck() {
|
||||
CSmartPtr<CWebSession> pSession = GetSession();
|
||||
std::shared_ptr<CWebSession> pSession = GetSession();
|
||||
return pSession->GetId().MD5();
|
||||
}
|
||||
|
||||
bool CWebSock::OnLogin(const CString& sUser, const CString& sPass) {
|
||||
DEBUG("=================== CWebSock::OnLogin()");
|
||||
m_spAuth = new CWebAuth(this, sUser, sPass);
|
||||
m_spAuth = std::make_shared<CWebAuth>(this, sUser, sPass);
|
||||
|
||||
// Some authentication module could need some time, block this socket
|
||||
// until then. CWebAuth will UnPauseRead().
|
||||
@@ -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();
|
||||
|
||||
@@ -1771,7 +1771,7 @@ CZNC::TrafficStatsMap CZNC::GetTrafficStats(TrafficStatsPair &Users,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CZNC::AuthUser(CSmartPtr<CAuthBase> AuthClass) {
|
||||
void CZNC::AuthUser(std::shared_ptr<CAuthBase> AuthClass) {
|
||||
// TODO unless the auth module calls it, CUser::IsHostAllowed() is not honoured
|
||||
bool bReturn = false;
|
||||
GLOBALMODULECALL(OnLoginAttempt(AuthClass), &bReturn);
|
||||
|
||||
Reference in New Issue
Block a user