mirror of
https://github.com/znc/znc.git
synced 2026-08-07 01:13:25 +02:00
clang-format: switch tabs to spaces
I like tabs, but I have to admit that spaces make source code more consistent, because every editor/viewer tends to render tabs differently :(
This commit is contained in:
+158
-158
@@ -20,204 +20,204 @@
|
||||
#include <znc/IRCNetwork.h>
|
||||
|
||||
class CIdentFileModule : public CModule {
|
||||
CString m_sOrigISpoof;
|
||||
CFile* m_pISpoofLockFile;
|
||||
CIRCSock* m_pIRCSock;
|
||||
CString m_sOrigISpoof;
|
||||
CFile* m_pISpoofLockFile;
|
||||
CIRCSock* m_pIRCSock;
|
||||
|
||||
public:
|
||||
MODCONSTRUCTOR(CIdentFileModule) {
|
||||
AddHelpCommand();
|
||||
AddCommand("GetFile", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::GetFile));
|
||||
AddCommand("SetFile", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::SetFile),
|
||||
"<file>");
|
||||
AddCommand("GetFormat", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::GetFormat));
|
||||
AddCommand("SetFormat", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::SetFormat),
|
||||
"<format>");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::Show));
|
||||
MODCONSTRUCTOR(CIdentFileModule) {
|
||||
AddHelpCommand();
|
||||
AddCommand("GetFile", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::GetFile));
|
||||
AddCommand("SetFile", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::SetFile),
|
||||
"<file>");
|
||||
AddCommand("GetFormat", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::GetFormat));
|
||||
AddCommand("SetFormat", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::SetFormat),
|
||||
"<format>");
|
||||
AddCommand("Show", static_cast<CModCommand::ModCmdFunc>(
|
||||
&CIdentFileModule::Show));
|
||||
|
||||
m_pISpoofLockFile = nullptr;
|
||||
m_pIRCSock = nullptr;
|
||||
}
|
||||
m_pISpoofLockFile = nullptr;
|
||||
m_pIRCSock = nullptr;
|
||||
}
|
||||
|
||||
virtual ~CIdentFileModule() { ReleaseISpoof(); }
|
||||
virtual ~CIdentFileModule() { ReleaseISpoof(); }
|
||||
|
||||
void GetFile(const CString& sLine) {
|
||||
PutModule("File is set to: " + GetNV("File"));
|
||||
}
|
||||
void GetFile(const CString& sLine) {
|
||||
PutModule("File is set to: " + GetNV("File"));
|
||||
}
|
||||
|
||||
void SetFile(const CString& sLine) {
|
||||
SetNV("File", sLine.Token(1, true));
|
||||
PutModule("File has been set to: " + GetNV("File"));
|
||||
}
|
||||
void SetFile(const CString& sLine) {
|
||||
SetNV("File", sLine.Token(1, true));
|
||||
PutModule("File has been set to: " + GetNV("File"));
|
||||
}
|
||||
|
||||
void SetFormat(const CString& sLine) {
|
||||
SetNV("Format", sLine.Token(1, true));
|
||||
PutModule("Format has been set to: " + GetNV("Format"));
|
||||
PutModule("Format would be expanded to: " +
|
||||
ExpandString(GetNV("Format")));
|
||||
}
|
||||
void SetFormat(const CString& sLine) {
|
||||
SetNV("Format", sLine.Token(1, true));
|
||||
PutModule("Format has been set to: " + GetNV("Format"));
|
||||
PutModule("Format would be expanded to: " +
|
||||
ExpandString(GetNV("Format")));
|
||||
}
|
||||
|
||||
void GetFormat(const CString& sLine) {
|
||||
PutModule("Format is set to: " + GetNV("Format"));
|
||||
PutModule("Format would be expanded to: " +
|
||||
ExpandString(GetNV("Format")));
|
||||
}
|
||||
void GetFormat(const CString& sLine) {
|
||||
PutModule("Format is set to: " + GetNV("Format"));
|
||||
PutModule("Format would be expanded to: " +
|
||||
ExpandString(GetNV("Format")));
|
||||
}
|
||||
|
||||
void Show(const CString& sLine) {
|
||||
PutModule("m_pISpoofLockFile = " +
|
||||
CString((long long)m_pISpoofLockFile));
|
||||
PutModule("m_pIRCSock = " + CString((long long)m_pIRCSock));
|
||||
if (m_pIRCSock) {
|
||||
PutModule("user/network - " +
|
||||
m_pIRCSock->GetNetwork()->GetUser()->GetUserName() + "/" +
|
||||
m_pIRCSock->GetNetwork()->GetName());
|
||||
} else {
|
||||
PutModule("identfile is free");
|
||||
}
|
||||
}
|
||||
void Show(const CString& sLine) {
|
||||
PutModule("m_pISpoofLockFile = " +
|
||||
CString((long long)m_pISpoofLockFile));
|
||||
PutModule("m_pIRCSock = " + CString((long long)m_pIRCSock));
|
||||
if (m_pIRCSock) {
|
||||
PutModule("user/network - " +
|
||||
m_pIRCSock->GetNetwork()->GetUser()->GetUserName() + "/" +
|
||||
m_pIRCSock->GetNetwork()->GetName());
|
||||
} else {
|
||||
PutModule("identfile is free");
|
||||
}
|
||||
}
|
||||
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (GetUser()->IsAdmin()) {
|
||||
HandleCommand(sCommand);
|
||||
} else {
|
||||
PutModule("Access denied");
|
||||
}
|
||||
}
|
||||
void OnModCommand(const CString& sCommand) override {
|
||||
if (GetUser()->IsAdmin()) {
|
||||
HandleCommand(sCommand);
|
||||
} else {
|
||||
PutModule("Access denied");
|
||||
}
|
||||
}
|
||||
|
||||
void SetIRCSock(CIRCSock* pIRCSock) {
|
||||
if (m_pIRCSock) {
|
||||
CZNC::Get().ResumeConnectQueue();
|
||||
}
|
||||
void SetIRCSock(CIRCSock* pIRCSock) {
|
||||
if (m_pIRCSock) {
|
||||
CZNC::Get().ResumeConnectQueue();
|
||||
}
|
||||
|
||||
m_pIRCSock = pIRCSock;
|
||||
m_pIRCSock = pIRCSock;
|
||||
|
||||
if (m_pIRCSock) {
|
||||
CZNC::Get().PauseConnectQueue();
|
||||
}
|
||||
}
|
||||
if (m_pIRCSock) {
|
||||
CZNC::Get().PauseConnectQueue();
|
||||
}
|
||||
}
|
||||
|
||||
bool WriteISpoof() {
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
return false;
|
||||
}
|
||||
bool WriteISpoof() {
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pISpoofLockFile = new CFile;
|
||||
if (!m_pISpoofLockFile->TryExLock(GetNV("File"), O_RDWR | O_CREAT)) {
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
return false;
|
||||
}
|
||||
m_pISpoofLockFile = new CFile;
|
||||
if (!m_pISpoofLockFile->TryExLock(GetNV("File"), O_RDWR | O_CREAT)) {
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
memset((char*)buf, 0, 1024);
|
||||
m_pISpoofLockFile->Read(buf, 1024);
|
||||
m_sOrigISpoof = buf;
|
||||
char buf[1024];
|
||||
memset((char*)buf, 0, 1024);
|
||||
m_pISpoofLockFile->Read(buf, 1024);
|
||||
m_sOrigISpoof = buf;
|
||||
|
||||
if (!m_pISpoofLockFile->Seek(0) || !m_pISpoofLockFile->Truncate()) {
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (!m_pISpoofLockFile->Seek(0) || !m_pISpoofLockFile->Truncate()) {
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
CString sData = ExpandString(GetNV("Format"));
|
||||
CString sData = ExpandString(GetNV("Format"));
|
||||
|
||||
// If the format doesn't contain anything expandable, we'll
|
||||
// assume this is an "old"-style format string.
|
||||
if (sData == GetNV("Format")) {
|
||||
sData.Replace("%", GetUser()->GetIdent());
|
||||
}
|
||||
// If the format doesn't contain anything expandable, we'll
|
||||
// assume this is an "old"-style format string.
|
||||
if (sData == GetNV("Format")) {
|
||||
sData.Replace("%", GetUser()->GetIdent());
|
||||
}
|
||||
|
||||
DEBUG("Writing [" + sData + "] to ident spoof file [" +
|
||||
m_pISpoofLockFile->GetLongName() + "] for user/network [" +
|
||||
GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "]");
|
||||
DEBUG("Writing [" + sData + "] to ident spoof file [" +
|
||||
m_pISpoofLockFile->GetLongName() + "] for user/network [" +
|
||||
GetUser()->GetUserName() + "/" + GetNetwork()->GetName() + "]");
|
||||
|
||||
m_pISpoofLockFile->Write(sData + "\n");
|
||||
m_pISpoofLockFile->Write(sData + "\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReleaseISpoof() {
|
||||
DEBUG("Releasing ident spoof for user/network [" +
|
||||
(m_pIRCSock
|
||||
? m_pIRCSock->GetNetwork()->GetUser()->GetUserName() + "/" +
|
||||
m_pIRCSock->GetNetwork()->GetName()
|
||||
: "<no user/network>") +
|
||||
"]");
|
||||
void ReleaseISpoof() {
|
||||
DEBUG("Releasing ident spoof for user/network [" +
|
||||
(m_pIRCSock
|
||||
? m_pIRCSock->GetNetwork()->GetUser()->GetUserName() + "/" +
|
||||
m_pIRCSock->GetNetwork()->GetName()
|
||||
: "<no user/network>") +
|
||||
"]");
|
||||
|
||||
SetIRCSock(nullptr);
|
||||
SetIRCSock(nullptr);
|
||||
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
if (m_pISpoofLockFile->Seek(0) && m_pISpoofLockFile->Truncate()) {
|
||||
m_pISpoofLockFile->Write(m_sOrigISpoof);
|
||||
}
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
if (m_pISpoofLockFile->Seek(0) && m_pISpoofLockFile->Truncate()) {
|
||||
m_pISpoofLockFile->Write(m_sOrigISpoof);
|
||||
}
|
||||
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
}
|
||||
}
|
||||
delete m_pISpoofLockFile;
|
||||
m_pISpoofLockFile = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
m_pISpoofLockFile = nullptr;
|
||||
m_pIRCSock = nullptr;
|
||||
bool OnLoad(const CString& sArgs, CString& sMessage) override {
|
||||
m_pISpoofLockFile = nullptr;
|
||||
m_pIRCSock = nullptr;
|
||||
|
||||
if (GetNV("Format").empty()) {
|
||||
SetNV("Format", "global { reply \"%ident%\" }");
|
||||
}
|
||||
if (GetNV("Format").empty()) {
|
||||
SetNV("Format", "global { reply \"%ident%\" }");
|
||||
}
|
||||
|
||||
if (GetNV("File").empty()) {
|
||||
SetNV("File", "~/.oidentd.conf");
|
||||
}
|
||||
if (GetNV("File").empty()) {
|
||||
SetNV("File", "~/.oidentd.conf");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
EModRet OnIRCConnecting(CIRCSock* pIRCSock) override {
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
DEBUG("Aborting connection, ident spoof lock file exists");
|
||||
PutModule(
|
||||
"Aborting connection, another user or network is currently "
|
||||
"connecting and using the ident spoof file");
|
||||
return HALTCORE;
|
||||
}
|
||||
EModRet OnIRCConnecting(CIRCSock* pIRCSock) override {
|
||||
if (m_pISpoofLockFile != nullptr) {
|
||||
DEBUG("Aborting connection, ident spoof lock file exists");
|
||||
PutModule(
|
||||
"Aborting connection, another user or network is currently "
|
||||
"connecting and using the ident spoof file");
|
||||
return HALTCORE;
|
||||
}
|
||||
|
||||
if (!WriteISpoof()) {
|
||||
DEBUG("identfile [" + GetNV("File") + "] could not be written");
|
||||
PutModule("[" + GetNV("File") +
|
||||
"] could not be written, retrying...");
|
||||
return HALTCORE;
|
||||
}
|
||||
if (!WriteISpoof()) {
|
||||
DEBUG("identfile [" + GetNV("File") + "] could not be written");
|
||||
PutModule("[" + GetNV("File") +
|
||||
"] could not be written, retrying...");
|
||||
return HALTCORE;
|
||||
}
|
||||
|
||||
SetIRCSock(pIRCSock);
|
||||
return CONTINUE;
|
||||
}
|
||||
SetIRCSock(pIRCSock);
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
void OnIRCConnected() override {
|
||||
if (m_pIRCSock == GetNetwork()->GetIRCSock()) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
void OnIRCConnected() override {
|
||||
if (m_pIRCSock == GetNetwork()->GetIRCSock()) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
|
||||
void OnIRCConnectionError(CIRCSock* pIRCSock) override {
|
||||
if (m_pIRCSock == pIRCSock) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
void OnIRCConnectionError(CIRCSock* pIRCSock) override {
|
||||
if (m_pIRCSock == pIRCSock) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
|
||||
void OnIRCDisconnected() override {
|
||||
if (m_pIRCSock == GetNetwork()->GetIRCSock()) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
void OnIRCDisconnected() override {
|
||||
if (m_pIRCSock == GetNetwork()->GetIRCSock()) {
|
||||
ReleaseISpoof();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
void TModInfo<CIdentFileModule>(CModInfo& Info) {
|
||||
Info.SetWikiPage("identfile");
|
||||
Info.SetWikiPage("identfile");
|
||||
}
|
||||
|
||||
GLOBALMODULEDEFS(
|
||||
|
||||
Reference in New Issue
Block a user