mirror of
https://github.com/znc/znc.git
synced 2026-06-30 15:01:54 +02: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;
|
||||
};
|
||||
|
||||
+1
-2
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user