mirror of
https://github.com/znc/znc.git
synced 2026-08-06 17:03:14 +02:00
Fix GetClients() const correctness
It’s dangerous to give a non-const reference to an internal container that the API users are not supposed to modify.
This commit is contained in:
@@ -148,7 +148,7 @@ public:
|
||||
CUser* GetUser() const { return m_pUser; }
|
||||
void SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect=true, bool bReconnect=true);
|
||||
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
|
||||
std::vector<CClient*>& GetClients();
|
||||
const std::vector<CClient*>& GetClients() const;
|
||||
const CIRCSock* GetIRCSock() const;
|
||||
CIRCSock* GetIRCSock();
|
||||
CString GetFullName();
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
CUser* GetUser();
|
||||
const CString& GetName() const;
|
||||
bool IsNetworkAttached() const { return !m_vClients.empty(); }
|
||||
std::vector<CClient*>& GetClients() { return m_vClients; }
|
||||
const std::vector<CClient*>& GetClients() const { return m_vClients; }
|
||||
|
||||
void SetUser(CUser *pUser);
|
||||
bool SetName(const CString& sName);
|
||||
|
||||
+1
-1
@@ -141,8 +141,8 @@ public:
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
std::vector<CClient*>& GetUserClients() { return m_vClients; }
|
||||
std::vector<CClient*> GetAllClients();
|
||||
const std::vector<CClient*>& GetUserClients() const { return m_vClients; }
|
||||
const CString& GetUserName() const;
|
||||
const CString& GetCleanUserName() const;
|
||||
const CString& GetNick(bool bAllowDefault = true) const;
|
||||
|
||||
+2
-2
@@ -141,8 +141,8 @@ void CChan::JoinUser(bool bForce, const CString& sKey, CClient* pClient) {
|
||||
CString sLine = sPre;
|
||||
CString sPerm, sNick;
|
||||
|
||||
vector<CClient*>& vpClients = m_pNetwork->GetClients();
|
||||
for (vector<CClient*>::iterator it = vpClients.begin(); it != vpClients.end(); ++it) {
|
||||
const vector<CClient*>& vpClients = m_pNetwork->GetClients();
|
||||
for (vector<CClient*>::const_iterator it = vpClients.begin(); it != vpClients.end(); ++it) {
|
||||
CClient* pThisClient;
|
||||
if (!pClient)
|
||||
pThisClient = *it;
|
||||
|
||||
+4
-4
@@ -271,7 +271,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
|
||||
// Relay to the rest of the clients that may be connected to this user
|
||||
if (m_pNetwork->IsChan(sTarget)) {
|
||||
vector<CClient*>& vClients = GetClients();
|
||||
const vector<CClient*>& vClients = GetClients();
|
||||
|
||||
for (unsigned int a = 0; a < vClients.size(); a++) {
|
||||
CClient* pClient = vClients[a];
|
||||
@@ -325,7 +325,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
}
|
||||
|
||||
// Relay to the rest of the clients that may be connected to this user
|
||||
vector<CClient*>& vClients = GetClients();
|
||||
const vector<CClient*>& vClients = GetClients();
|
||||
|
||||
for (unsigned int a = 0; a < vClients.size(); a++) {
|
||||
CClient* pClient = vClients[a];
|
||||
@@ -394,7 +394,7 @@ void CClient::ReadLine(const CString& sData) {
|
||||
// Relay to the rest of the clients that may be connected to this user
|
||||
|
||||
if (m_pNetwork->IsChan(sTarget)) {
|
||||
vector<CClient*>& vClients = GetClients();
|
||||
const vector<CClient*>& vClients = GetClients();
|
||||
|
||||
for (unsigned int a = 0; a < vClients.size(); a++) {
|
||||
CClient* pClient = vClients[a];
|
||||
@@ -575,7 +575,7 @@ void CClient::SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect, bool bReconnec
|
||||
}
|
||||
}
|
||||
|
||||
vector<CClient*>& CClient::GetClients() {
|
||||
const vector<CClient*>& CClient::GetClients() const {
|
||||
if (m_pNetwork) {
|
||||
return m_pNetwork->GetClients();
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ protected:
|
||||
pIRCSock->PutIRC("PING :ZNC");
|
||||
}
|
||||
|
||||
vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
const vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
for (size_t b = 0; b < vClients.size(); b++) {
|
||||
CClient* pClient = vClients[b];
|
||||
|
||||
|
||||
+5
-5
@@ -181,7 +181,7 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
m_bAuthed = true;
|
||||
m_pNetwork->PutStatus("Connected!");
|
||||
|
||||
vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
const vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
|
||||
for (unsigned int a = 0; a < vClients.size(); a++) {
|
||||
CClient* pClient = vClients[a];
|
||||
@@ -354,8 +354,8 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
if (m_bNamesx && (sNick.size() > 1) && IsPermChar(sNick[1])) {
|
||||
// sLine uses multi-prefix
|
||||
|
||||
vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
vector<CClient*>::iterator it;
|
||||
const vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
vector<CClient*>::const_iterator it;
|
||||
for (it = vClients.begin(); it != vClients.end(); ++it) {
|
||||
CClient *pClient = *it;
|
||||
|
||||
@@ -1233,8 +1233,8 @@ CString CIRCSock::GetISupport(const CString& sKey, const CString& sDefault) cons
|
||||
}
|
||||
|
||||
void CIRCSock::ForwardRaw353(const CString& sLine) const {
|
||||
vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
vector<CClient*>::iterator it;
|
||||
const vector<CClient*>& vClients = m_pNetwork->GetClients();
|
||||
vector<CClient*>::const_iterator it;
|
||||
|
||||
for (it = vClients.begin(); it != vClients.end(); ++it) {
|
||||
ForwardRaw353(sLine, *it);
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ public:
|
||||
private:
|
||||
protected:
|
||||
virtual void RunJob() {
|
||||
vector<CClient*>& vUserClients = m_pUser->GetUserClients();
|
||||
const vector<CClient*>& vUserClients = m_pUser->GetUserClients();
|
||||
for (size_t c = 0; c < vUserClients.size(); ++c) {
|
||||
CClient* pUserClient = vUserClients[c];
|
||||
|
||||
@@ -659,7 +659,7 @@ void CUser::CloneNetworks(const CUser& User) {
|
||||
// have requested the rehash. Then when we do
|
||||
// client->PutStatus("Rehashing succeeded!") we would
|
||||
// crash if there was no client anymore.
|
||||
vector<CClient*>& vClients = FindNetwork(*it)->GetClients();
|
||||
const vector<CClient*>& vClients = FindNetwork(*it)->GetClients();
|
||||
|
||||
while (vClients.begin() != vClients.end()) {
|
||||
CClient *pClient = vClients.front();
|
||||
|
||||
Reference in New Issue
Block a user