mirror of
https://github.com/znc/znc.git
synced 2026-07-06 01:41:12 +02:00
Merge branch 'master' into sasl
Conflicts: include/znc/Client.h src/Client.cpp src/Modules.cpp test/integration/tests/modules.cpp
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
# Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
# Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+16
-90
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -98,83 +98,7 @@ class CClientAuth : public CAuthBase {
|
||||
|
||||
class CClient : public CIRCSocket {
|
||||
public:
|
||||
CClient()
|
||||
: CIRCSocket(),
|
||||
m_bGotPass(false),
|
||||
m_bGotNick(false),
|
||||
m_bGotUser(false),
|
||||
m_bInCap(false),
|
||||
m_bCapNotify(false),
|
||||
m_bAwayNotify(false),
|
||||
m_bAccountNotify(false),
|
||||
m_bAccountTag(false),
|
||||
m_bExtendedJoin(false),
|
||||
m_bNamesx(false),
|
||||
m_bUHNames(false),
|
||||
m_bAway(false),
|
||||
m_bServerTime(false),
|
||||
m_bBatch(false),
|
||||
m_bEchoMessage(false),
|
||||
m_bSelfMessage(false),
|
||||
m_bSASL(false),
|
||||
m_bSASLAuthenticating(false),
|
||||
m_bPlaybackActive(false),
|
||||
m_pUser(nullptr),
|
||||
m_pNetwork(nullptr),
|
||||
m_sNick("unknown-nick"),
|
||||
m_sPass(""),
|
||||
m_sUser(""),
|
||||
m_sNetwork(""),
|
||||
m_sIdentifier(""),
|
||||
m_sSASLBuffer(""),
|
||||
m_sSASLMechanism(""),
|
||||
m_sSASLUser(""),
|
||||
m_spAuth(),
|
||||
m_ssAcceptedCaps(),
|
||||
m_ssSupportedTags(),
|
||||
m_mCoreCaps({
|
||||
{"multi-prefix",
|
||||
{false, [this](bool bVal) { m_bNamesx = bVal; }}},
|
||||
{"userhost-in-names",
|
||||
{false, [this](bool bVal) { m_bUHNames = bVal; }}},
|
||||
{"echo-message",
|
||||
{false, [this](bool bVal) { m_bEchoMessage = bVal; }}},
|
||||
{"server-time",
|
||||
{false, [this](bool bVal) {
|
||||
m_bServerTime = bVal;
|
||||
SetTagSupport("time", bVal);
|
||||
}}},
|
||||
{"batch", {false, [this](bool bVal) {
|
||||
m_bBatch = bVal;
|
||||
SetTagSupport("batch", bVal);
|
||||
}}},
|
||||
{"cap-notify",
|
||||
{false, [this](bool bVal) { m_bCapNotify = bVal; }}},
|
||||
{"away-notify",
|
||||
{true, [this](bool bVal) { m_bAwayNotify = bVal; }}},
|
||||
{"account-notify",
|
||||
{true, [this](bool bVal) { m_bAccountNotify = bVal; }}},
|
||||
{"account-tag",
|
||||
{true, [this](bool bVal) {
|
||||
m_bAccountTag = bVal;
|
||||
SetTagSupport("account", bVal);
|
||||
}}},
|
||||
{"extended-join",
|
||||
{true, [this](bool bVal) { m_bExtendedJoin = bVal; }}},
|
||||
{"sasl", {false, [this](bool bVal) { m_bSASL = bVal; m_bSASLAuthenticating = bVal; }}},
|
||||
}) {
|
||||
EnableReadLine();
|
||||
// RFC says a line can have 512 chars max, but we are
|
||||
// a little more gentle ;)
|
||||
SetMaxBufferThreshold(1024);
|
||||
|
||||
// For compatibility with older clients
|
||||
m_mCoreCaps["znc.in/server-time-iso"] = m_mCoreCaps["server-time"];
|
||||
m_mCoreCaps["znc.in/batch"] = m_mCoreCaps["batch"];
|
||||
m_mCoreCaps["znc.in/self-message"] = {
|
||||
false, [this](bool bVal) { m_bSelfMessage = bVal; }};
|
||||
}
|
||||
|
||||
CClient();
|
||||
virtual ~CClient();
|
||||
|
||||
CClient(const CClient&) = delete;
|
||||
@@ -187,13 +111,15 @@ class CClient : public CIRCSocket {
|
||||
CString GetNick(bool bAllowIRCNick = true) const;
|
||||
CString GetNickMask() const;
|
||||
CString GetIdentifier() const { return m_sIdentifier; }
|
||||
unsigned short int CapVersion() const { return m_uCapVersion; }
|
||||
bool HasCap302() const { return CapVersion() >= 302; }
|
||||
bool HasCapNotify() const { return m_bCapNotify; }
|
||||
bool HasAwayNotify() const { return m_bAwayNotify; }
|
||||
bool HasAccountNotify() const { return m_bAccountNotify; }
|
||||
bool HasAccountTag() const { return m_bAccountTag; }
|
||||
bool HasExtendedJoin() const { return m_bExtendedJoin; }
|
||||
bool HasNamesx() const { return m_bNamesx; }
|
||||
bool HasUHNames() const { return m_bUHNames; }
|
||||
bool HasChgHost() const { return m_bChgHost; }
|
||||
bool IsAway() const { return m_bAway; }
|
||||
bool HasServerTime() const { return m_bServerTime; }
|
||||
bool HasBatch() const { return m_bBatch; }
|
||||
@@ -299,8 +225,9 @@ class CClient : public CIRCSocket {
|
||||
*/
|
||||
void SetTagSupport(const CString& sTag, bool bState);
|
||||
|
||||
void NotifyServerDependentCaps(const SCString& ssCaps);
|
||||
void ClearServerDependentCaps();
|
||||
/** Notifies client about one specific cap which server has just notified us about.
|
||||
*/
|
||||
void NotifyServerDependentCap(const CString& sCap, bool bValue, const CString& sValue);
|
||||
|
||||
void ReadLine(const CString& sData) override;
|
||||
bool SendMotd();
|
||||
@@ -364,14 +291,15 @@ class CClient : public CIRCSocket {
|
||||
bool m_bGotPass;
|
||||
bool m_bGotNick;
|
||||
bool m_bGotUser;
|
||||
unsigned short int m_uCapVersion;
|
||||
bool m_bInCap;
|
||||
bool m_bCapNotify;
|
||||
bool m_bAwayNotify;
|
||||
bool m_bAccountNotify;
|
||||
bool m_bAccountTag;
|
||||
bool m_bExtendedJoin;
|
||||
bool m_bNamesx;
|
||||
bool m_bUHNames;
|
||||
bool m_bChgHost;
|
||||
bool m_bAway;
|
||||
bool m_bServerTime;
|
||||
bool m_bBatch;
|
||||
@@ -393,16 +321,14 @@ class CClient : public CIRCSocket {
|
||||
std::shared_ptr<CAuthBase> m_spAuth;
|
||||
SCString m_ssAcceptedCaps;
|
||||
SCString m_ssSupportedTags;
|
||||
// The capabilities supported by the ZNC core - capability names mapped
|
||||
// to a pair which contains a bool describing whether the capability is
|
||||
// server-dependent, and a capability value change handler.
|
||||
std::map<CString, std::pair<bool, std::function<void(bool bVal)>>>
|
||||
m_mCoreCaps;
|
||||
// A subset of CIRCSock::GetAcceptedCaps(), the caps that can be listed
|
||||
// in CAP LS and may be notified to the client with CAP NEW (cap-notify).
|
||||
SCString m_ssServerDependentCaps;
|
||||
// The capabilities supported by the ZNC core - capability names mapped to
|
||||
// change handler. Note: this lists caps which don't require support on IRC
|
||||
// server.
|
||||
static const std::map<CString, std::function<void(CClient*, bool bVal)>>&
|
||||
CoreCaps();
|
||||
|
||||
friend class ClientTest;
|
||||
friend class CCoreCaps;
|
||||
};
|
||||
|
||||
#endif // !ZNC_CLIENT_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -156,6 +156,8 @@ class CIRCNetwork : private CCoreTranslationMixin {
|
||||
void IRCConnected();
|
||||
void IRCDisconnected();
|
||||
void CheckIRCConnect();
|
||||
void NotifyClientsAboutServerDependentCap(const CString& sCap, bool bValue);
|
||||
bool IsServerCapAccepted(const CString& sCap) const;
|
||||
|
||||
bool PutIRC(const CString& sLine);
|
||||
bool PutIRC(const CMessage& Message);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -131,6 +131,7 @@ class CIRCSock : public CIRCSocket {
|
||||
unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
|
||||
EChanModeArgs GetModeType(char cMode) const;
|
||||
char GetPermFromMode(char cMode) const;
|
||||
char GetModeFromPerm(char cPerm) const;
|
||||
const std::map<char, EChanModeArgs>& GetChanModes() const {
|
||||
return m_mceChanModes;
|
||||
}
|
||||
@@ -150,7 +151,6 @@ class CIRCSock : public CIRCSocket {
|
||||
bool HasUHNames() const { return m_bUHNames; }
|
||||
bool HasAwayNotify() const { return m_bAwayNotify; }
|
||||
bool HasAccountNotify() const { return m_bAccountNotify; }
|
||||
bool HasAccountTag() const { return m_bAccountTag; }
|
||||
bool HasExtendedJoin() const { return m_bExtendedJoin; }
|
||||
bool HasServerTime() const { return m_bServerTime; }
|
||||
const std::set<char>& GetUserModes() const {
|
||||
@@ -162,6 +162,8 @@ class CIRCSock : public CIRCSocket {
|
||||
bool IsCapAccepted(const CString& sCap) {
|
||||
return 1 == m_ssAcceptedCaps.count(sCap);
|
||||
}
|
||||
CString GetCapLsValue(const CString& sKey,
|
||||
const CString& sDefault = "") const;
|
||||
const MCString& GetISupport() const { return m_mISupport; }
|
||||
CString GetISupport(const CString& sKey,
|
||||
const CString& sDefault = "") const;
|
||||
@@ -176,6 +178,7 @@ class CIRCSock : public CIRCSocket {
|
||||
bool OnActionMessage(CActionMessage& Message);
|
||||
bool OnAwayMessage(CMessage& Message);
|
||||
bool OnCapabilityMessage(CMessage& Message);
|
||||
bool OnChgHostMessage(CChgHostMessage& Message);
|
||||
bool OnCTCPMessage(CCTCPMessage& Message);
|
||||
bool OnErrorMessage(CMessage& Message);
|
||||
bool OnInviteMessage(CMessage& Message);
|
||||
@@ -192,7 +195,7 @@ class CIRCSock : public CIRCSocket {
|
||||
bool OnTextMessage(CTextMessage& Message);
|
||||
bool OnTopicMessage(CTopicMessage& Message);
|
||||
bool OnWallopsMessage(CMessage& Message);
|
||||
bool OnServerCapAvailable(const CString& sCap);
|
||||
bool OnServerCapAvailable(const CString& sCap, const CString& sValue);
|
||||
// !Message Handlers
|
||||
|
||||
void SetNick(const CString& sNick);
|
||||
@@ -208,7 +211,6 @@ class CIRCSock : public CIRCSocket {
|
||||
bool m_bUHNames;
|
||||
bool m_bAwayNotify;
|
||||
bool m_bAccountNotify;
|
||||
bool m_bAccountTag;
|
||||
bool m_bExtendedJoin;
|
||||
bool m_bServerTime;
|
||||
CString m_sPerms;
|
||||
@@ -223,6 +225,7 @@ class CIRCSock : public CIRCSocket {
|
||||
unsigned int m_uCapPaused;
|
||||
SCString m_ssAcceptedCaps;
|
||||
SCString m_ssPendingCaps;
|
||||
MCString m_msCapLsValues;
|
||||
time_t m_lastCTCP;
|
||||
unsigned int m_uNumCTCP;
|
||||
static const time_t m_uCTCPFloodTime;
|
||||
@@ -237,6 +240,7 @@ class CIRCSock : public CIRCSocket {
|
||||
VCString m_vsSSLError;
|
||||
|
||||
friend class CIRCFloodTimer;
|
||||
friend class CCoreCaps;
|
||||
};
|
||||
|
||||
#endif // !ZNC_IRCSOCK_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+16
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,19 +17,6 @@
|
||||
#ifndef ZNC_MESSAGE_H
|
||||
#define ZNC_MESSAGE_H
|
||||
|
||||
// Remove this after Feb 2016 when Debian 7 is EOL
|
||||
#if __cpp_ref_qualifiers >= 200710
|
||||
#define ZNC_LVREFQUAL &
|
||||
#elif defined(__clang__)
|
||||
#define ZNC_LVREFQUAL &
|
||||
#elif __GNUC__ > 4 || \
|
||||
__GNUC__ == 4 && (__GNUC_MINOR__ > 8 || \
|
||||
__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ >= 1)
|
||||
#define ZNC_LVREFQUAL &
|
||||
#else
|
||||
#define ZNC_LVREFQUAL
|
||||
#endif
|
||||
|
||||
#ifdef SWIG
|
||||
#define ZNC_MSG_DEPRECATED(msg)
|
||||
#else
|
||||
@@ -81,6 +68,7 @@ class CMessage {
|
||||
Authenticate,
|
||||
Away,
|
||||
Capability,
|
||||
ChgHost,
|
||||
CTCP,
|
||||
Error,
|
||||
Invite,
|
||||
@@ -135,6 +123,7 @@ class CMessage {
|
||||
*/
|
||||
VCString GetParamsSplit(unsigned int uIdx, unsigned int uLen = -1) const;
|
||||
void SetParams(const VCString& vsParams);
|
||||
void SetParams(VCString&& vsParams);
|
||||
|
||||
/// @deprecated use GetParamsColon() instead.
|
||||
CString GetParams(unsigned int uIdx, unsigned int uLen = -1) const
|
||||
@@ -167,7 +156,7 @@ class CMessage {
|
||||
// Implicit and explicit conversion to a subclass reference.
|
||||
#ifndef SWIG
|
||||
template <typename M>
|
||||
M& As() ZNC_LVREFQUAL {
|
||||
M& As() & {
|
||||
static_assert(std::is_base_of<CMessage, M>{},
|
||||
"Must be subclass of CMessage");
|
||||
static_assert(sizeof(M) == sizeof(CMessage),
|
||||
@@ -176,7 +165,7 @@ class CMessage {
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
const M& As() const ZNC_LVREFQUAL {
|
||||
const M& As() const& {
|
||||
static_assert(std::is_base_of<CMessage, M>{},
|
||||
"Must be subclass of CMessage");
|
||||
static_assert(sizeof(M) == sizeof(CMessage),
|
||||
@@ -186,12 +175,12 @@ class CMessage {
|
||||
|
||||
template <typename M, typename = typename std::enable_if<
|
||||
std::is_base_of<CMessage, M>{}>::type>
|
||||
operator M&() ZNC_LVREFQUAL {
|
||||
operator M&() & {
|
||||
return As<M>();
|
||||
}
|
||||
template <typename M, typename = typename std::enable_if<
|
||||
std::is_base_of<CMessage, M>{}>::type>
|
||||
operator const M&() const ZNC_LVREFQUAL {
|
||||
operator const M&() const& {
|
||||
return As<M>();
|
||||
}
|
||||
// REGISTER_ZNC_MESSAGE allows SWIG to instantiate correct .As<> calls.
|
||||
@@ -354,4 +343,13 @@ class CTopicMessage : public CTargetMessage {
|
||||
};
|
||||
REGISTER_ZNC_MESSAGE(CTopicMessage);
|
||||
|
||||
class CChgHostMessage : public CMessage {
|
||||
public:
|
||||
CString GetNewIdent() const { return GetParam(0); }
|
||||
void SetNewIdent(const CString& sIdent) { SetParam(0, sIdent); }
|
||||
CString GetNewHost() const { return GetParam(1); }
|
||||
void SetNewHost(const CString& sHost) { SetParam(1, sHost); }
|
||||
};
|
||||
REGISTER_ZNC_MESSAGE(CChgHostMessage);
|
||||
|
||||
#endif // !ZNC_MESSAGE_H
|
||||
|
||||
+80
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <znc/main.h>
|
||||
#include <znc/Translation.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
#include <sys/time.h>
|
||||
@@ -166,6 +167,19 @@ class CFPTimer;
|
||||
class CSockManager;
|
||||
// !Forward Declarations
|
||||
|
||||
class CCapability {
|
||||
public:
|
||||
virtual ~CCapability() = default;
|
||||
virtual void OnServerChangedSupport(CIRCNetwork* pNetwork, bool bState) {}
|
||||
virtual void OnClientChangedSupport(CClient* pClient, bool bState) {}
|
||||
|
||||
CModule* GetModule() { return m_pModule; }
|
||||
void SetModule(CModule* p) { m_pModule = p; }
|
||||
|
||||
protected:
|
||||
CModule* m_pModule = nullptr;
|
||||
};
|
||||
|
||||
class CTimer : public CCron {
|
||||
public:
|
||||
CTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles,
|
||||
@@ -998,13 +1012,28 @@ class CModule {
|
||||
virtual EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic);
|
||||
|
||||
/** Called for every CAP received via CAP LS from server.
|
||||
* If you need to also advertise the cap to clients, use
|
||||
* AddServerDependentCapability() instead.
|
||||
* @param sCap capability supported by server.
|
||||
* @return true if your module supports this CAP and
|
||||
* needs to turn it on with CAP REQ.
|
||||
*/
|
||||
virtual bool OnServerCapAvailable(const CString& sCap);
|
||||
/** Called for every CAP received via CAP LS from server.
|
||||
* By default just calls OnServerCapAvailable() without sValue, so
|
||||
* overriding one of the two is enough.
|
||||
* If you need to also advertise the cap to clients, use
|
||||
* AddServerDependentCapability() instead.
|
||||
* @param sCap capability name supported by server.
|
||||
* @param sValue value.
|
||||
* @return true if your module supports this CAP and
|
||||
* needs to turn it on with CAP REQ.
|
||||
*/
|
||||
virtual bool OnServerCap302Available(const CString& sCap, const CString& sValue);
|
||||
/** Called for every CAP accepted or rejected by server
|
||||
* (with CAP ACK or CAP NAK after our CAP REQ).
|
||||
* If you need to also advertise the cap to clients, use
|
||||
* AddServerDependentCapability() instead.
|
||||
* @param sCap capability accepted/rejected by server.
|
||||
* @param bSuccess true if capability was accepted, false if rejected.
|
||||
*/
|
||||
@@ -1283,8 +1312,32 @@ class CModule {
|
||||
virtual EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine);
|
||||
virtual EModRet OnUnknownUserRawMessage(CMessage& Message);
|
||||
|
||||
/** Called after login, and also during JumpNetwork. */
|
||||
virtual void OnClientAttached();
|
||||
/** Called upon disconnect, and also during JumpNetwork. */
|
||||
virtual void OnClientDetached();
|
||||
|
||||
#ifndef SWIG
|
||||
/** Simple API to support client capabilities which depend on server to support that capability.
|
||||
* It is built on top of other CAP related API, but removes boilerplate,
|
||||
* and handles some tricky cases related to cap-notify and JumpNetwork. To
|
||||
* use, create a subclass of CCapability, and pass to this function; it
|
||||
* will automatically set the module pointer, then call the callbacks to
|
||||
* notify you when server and client accepted support of the capability, or
|
||||
* stopped supporting it. Note that it's not a strict toggle: e.g.
|
||||
* sometimes client will disable the cap even when it was already disabled
|
||||
* for that client.
|
||||
* For perl and python modules, this function accepts 3 parameters:
|
||||
* name, server callback, client callback; signatures of the callbacks are
|
||||
* the same as of the virtual functions you'd implement in C++.
|
||||
*/
|
||||
void AddServerDependentCapability(const CString& sName, std::unique_ptr<CCapability> pCap);
|
||||
#endif
|
||||
|
||||
/** Called when a client told us CAP LS. Use ssCaps.insert("cap-name")
|
||||
* for announcing capabilities which your module supports.
|
||||
* If you need to adverite the cap to clients only when it's also supported
|
||||
* by the server, use AddServerDependentCapability() instead.
|
||||
* @param pClient The client which requested the list.
|
||||
* @param ssCaps set of caps which will be sent to client.
|
||||
*/
|
||||
@@ -1298,6 +1351,8 @@ class CModule {
|
||||
virtual bool IsClientCapSupported(CClient* pClient, const CString& sCap,
|
||||
bool bState);
|
||||
/** Called when we actually need to turn a capability on or off for a client.
|
||||
* If you need to adverite the cap to clients only when it's also supported
|
||||
* by the server, use AddServerDependentCapability() instead.
|
||||
* If implementing a custom capability, make sure to call
|
||||
* pClient->SetTagSupport("tag-name", bState) for each tag that the
|
||||
* capability provides.
|
||||
@@ -1388,6 +1443,26 @@ class CModule {
|
||||
const CString& sContext = "") const;
|
||||
#endif
|
||||
|
||||
// Default implementations of several callbacks to make
|
||||
// AddServerDependentCapability work in modpython/modperl.
|
||||
// Don't worry about existence of these functions.
|
||||
bool InternalServerDependentCapsOnServerCap302Available(
|
||||
const CString& sCap, const CString& sValue);
|
||||
void InternalServerDependentCapsOnServerCapResult(const CString& sCap,
|
||||
bool bSuccess);
|
||||
void InternalServerDependentCapsOnClientCapLs(CClient* pClient,
|
||||
SCString& ssCaps);
|
||||
bool InternalServerDependentCapsIsClientCapSupported(CClient* pClient,
|
||||
const CString& sCap,
|
||||
bool bState);
|
||||
void InternalServerDependentCapsOnClientCapRequest(CClient* pClient,
|
||||
const CString& sCap,
|
||||
bool bState);
|
||||
void InternalServerDependentCapsOnClientAttached();
|
||||
void InternalServerDependentCapsOnClientDetached();
|
||||
void InternalServerDependentCapsOnIRCConnected();
|
||||
void InternalServerDependentCapsOnIRCDisconnected();
|
||||
|
||||
protected:
|
||||
CModInfo::EModuleType m_eType;
|
||||
CString m_sDescription;
|
||||
@@ -1407,6 +1482,7 @@ class CModule {
|
||||
CString m_sArgs;
|
||||
CString m_sModPath;
|
||||
CTranslationDomainRefHolder m_Translation;
|
||||
std::map<CString, std::unique_ptr<CCapability>> m_mServerDependentCaps;
|
||||
|
||||
private:
|
||||
MCString
|
||||
@@ -1570,8 +1646,10 @@ class CModules : public std::vector<CModule*>, private CCoreTranslationMixin {
|
||||
bool OnSendToClientMessage(CMessage& Message);
|
||||
bool OnSendToIRC(CString& sLine);
|
||||
bool OnSendToIRCMessage(CMessage& Message);
|
||||
bool OnClientAttached();
|
||||
bool OnClientDetached();
|
||||
|
||||
bool OnServerCapAvailable(const CString& sCap);
|
||||
bool OnServerCapAvailable(const CString& sCap, const CString& sValue);
|
||||
bool OnServerCapResult(const CString& sCap, bool bSuccess);
|
||||
|
||||
CModule* FindModule(const CString& sModule) const;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <znc/ZNCString.h>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
||||
struct CTranslationInfo {
|
||||
static std::map<CString, CTranslationInfo> GetTranslations();
|
||||
@@ -83,20 +84,18 @@ class CDelayedTranslation {
|
||||
|
||||
class COptionalTranslation {
|
||||
public:
|
||||
COptionalTranslation(const CString& sText)
|
||||
: m_bTranslating(false), m_sText(sText) {}
|
||||
COptionalTranslation(const CString& sText) : m_text(sText) {}
|
||||
COptionalTranslation(const char* s) : COptionalTranslation(CString(s)) {}
|
||||
COptionalTranslation(const CDelayedTranslation& dTranslation)
|
||||
: m_bTranslating(true), m_dTranslation(dTranslation) {}
|
||||
COptionalTranslation(const CDelayedTranslation& dTranslation) : m_text(dTranslation) {}
|
||||
CString Resolve() const {
|
||||
return m_bTranslating ? m_dTranslation.Resolve() : m_sText;
|
||||
if (m_text.index() == 0) {
|
||||
return std::get<0>(m_text);
|
||||
}
|
||||
return std::get<1>(m_text).Resolve();
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_bTranslating;
|
||||
// TODO switch to std::variant<CString, CDelayedTranslation> after C++17
|
||||
CString m_sText;
|
||||
CDelayedTranslation m_dTranslation;
|
||||
std::variant<CString, CDelayedTranslation> m_text;
|
||||
};
|
||||
|
||||
// Used by everything except modules.
|
||||
|
||||
+11
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -45,24 +45,27 @@ class CUser : private CCoreTranslationMixin {
|
||||
|
||||
bool ParseConfig(CConfig* Config, CString& sError);
|
||||
|
||||
// TODO refactor this
|
||||
enum eHashType {
|
||||
HASH_NONE,
|
||||
HASH_MD5,
|
||||
HASH_SHA256,
|
||||
HASH_ARGON2ID,
|
||||
|
||||
HASH_DEFAULT = HASH_SHA256
|
||||
// This should be kept in sync with CUtils::SaltedHash
|
||||
#if ZNC_HAVE_ARGON
|
||||
HASH_DEFAULT = HASH_ARGON2ID,
|
||||
#else
|
||||
HASH_DEFAULT = HASH_SHA256,
|
||||
#endif
|
||||
};
|
||||
|
||||
// If you change the default hash here and in HASH_DEFAULT,
|
||||
// don't forget CUtils::sDefaultHash!
|
||||
// TODO refactor this
|
||||
static CString SaltedHash(const CString& sPass, const CString& sSalt) {
|
||||
return CUtils::SaltedSHA256Hash(sPass, sSalt);
|
||||
return CUtils::SaltedHash(sPass, sSalt);
|
||||
}
|
||||
|
||||
CConfig ToConfig() const;
|
||||
bool CheckPass(const CString& sPass) const;
|
||||
/** Checks password, may upgrade the hash method. */
|
||||
bool CheckPass(const CString& sPass);
|
||||
bool AddAllowedHost(const CString& sHostMask);
|
||||
bool RemAllowedHost(const CString& sHostMask);
|
||||
void ClearAllowedHosts();
|
||||
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,15 +51,16 @@ class CUtils {
|
||||
static void PrintAction(const CString& sMessage);
|
||||
static void PrintStatus(bool bSuccess, const CString& sMessage = "");
|
||||
|
||||
#ifndef SWIGPERL
|
||||
// TODO refactor this
|
||||
static const CString sDefaultHash;
|
||||
#endif
|
||||
/** Asks password from stdin, with confirmation.
|
||||
*
|
||||
* @returns Piece of znc.conf with <Pass> block
|
||||
* */
|
||||
static CString AskSaltedHashPassForConfig();
|
||||
|
||||
static CString GetSaltedHashPass(CString& sSalt);
|
||||
static CString GetSalt();
|
||||
static CString SaltedMD5Hash(const CString& sPass, const CString& sSalt);
|
||||
static CString SaltedSHA256Hash(const CString& sPass, const CString& sSalt);
|
||||
static CString SaltedHash(const CString& sPass, const CString& sSalt);
|
||||
static CString GetPass(const CString& sPrompt);
|
||||
static bool GetInput(const CString& sPrompt, CString& sRet,
|
||||
const CString& sDefault = "",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -57,9 +57,16 @@ extern const char* ZNC_VERSION_EXTRA;
|
||||
#define ZNC_VERSION_TEXT_I18N "no"
|
||||
#endif
|
||||
|
||||
// This is only here because HASH_DEFAULT has different value
|
||||
#ifdef ZNC_HAVE_ARGON
|
||||
#define ZNC_VERSION_TEXT_ARGON "yes"
|
||||
#else
|
||||
#define ZNC_VERSION_TEXT_ARGON "no"
|
||||
#endif
|
||||
|
||||
#define ZNC_COMPILE_OPTIONS_STRING \
|
||||
"IPv6: " ZNC_VERSION_TEXT_IPV6 ", SSL: " ZNC_VERSION_TEXT_SSL \
|
||||
", DNS: " ZNC_VERSION_TEXT_DNS ", charset: " ZNC_VERSION_TEXT_ICU \
|
||||
", i18n: " ZNC_VERSION_TEXT_I18N
|
||||
", i18n: " ZNC_VERSION_TEXT_I18N ", Argon2: " ZNC_VERSION_TEXT_ARGON
|
||||
|
||||
#endif // !ZNC_VERSION_H
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2023 ZNC, see the NOTICE file for details.
|
||||
* Copyright (C) 2004-2025 ZNC, see the NOTICE file for details.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,6 +35,7 @@
|
||||
#cmakedefine HAVE_IPV6 1
|
||||
#cmakedefine HAVE_ZLIB 1
|
||||
#cmakedefine HAVE_I18N 1
|
||||
#cmakedefine ZNC_HAVE_ARGON 1
|
||||
#cmakedefine CSOCK_USE_POLL 1
|
||||
|
||||
#cmakedefine HAVE_GETOPT_LONG 1
|
||||
|
||||
Reference in New Issue
Block a user