Permalink
Browse files

Merge pull request #598 from jpnurmi/query

Full-fledged query buffers
  • Loading branch information...
2 parents e97a3ce + 287a020 commit 83a25c5355f83b391a18cae42f8027088ec7520b @DarthGandalf DarthGandalf committed Aug 7, 2014
View
@@ -42,7 +42,7 @@ endif
LIB_SRCS := ZNCString.cpp Csocket.cpp znc.cpp IRCNetwork.cpp User.cpp IRCSock.cpp \
Client.cpp Chan.cpp Nick.cpp Server.cpp Modules.cpp MD5.cpp Buffer.cpp Utils.cpp \
FileUtils.cpp HTTPSock.cpp Template.cpp ClientCommand.cpp Socket.cpp SHA256.cpp \
- WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp Threads.cpp version.cpp
+ WebModules.cpp Listener.cpp Config.cpp ZNCDebug.cpp Threads.cpp version.cpp Query.cpp
LIB_SRCS := $(addprefix src/,$(LIB_SRCS))
BIN_SRCS := src/main.cpp
LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS))
View
1 NOTICE
@@ -46,5 +46,6 @@ Michael "adgar" Edgar <adgar@carboni.ca>
Jens-Andre "vain" Koch <jakoch@web.de>
Heiko Hund <heiko@ist.eigentlich.net> - cyrusauth module
Philippe (http://sourceforge.net/users/cycomate) - kickrejoin module
+J-P Nurmi <jpnurmi@gmail.com>
If you did something useful and want to be listed here too, add yourself and submit the patch.
View
@@ -30,6 +30,7 @@ class CConfig;
class CClient;
class CConfig;
class CChan;
+class CQuery;
class CServer;
class CIRCSock;
class CIRCNetworkPingTimer;
@@ -96,6 +97,12 @@ class CIRCNetwork {
void JoinChans();
void JoinChans(std::set<CChan*>& sChans);
+ const std::vector<CQuery*>& GetQueries() const;
+ CQuery* FindQuery(const CString& sName) const;
+ std::vector<CQuery*> FindQueries(const CString& sWild) const;
+ CQuery* AddQuery(const CString& sName);
+ bool DelQuery(const CString& sName);
+
const CString& GetChanPrefixes() const { return m_sChanPrefixes; };
void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; };
bool IsChan(const CString& sChan) const;
@@ -144,9 +151,9 @@ class CIRCNetwork {
void UpdateMotdBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_MotdBuffer.UpdateLine(sMatch, sFormat, sText); }
void ClearMotdBuffer() { m_MotdBuffer.Clear(); }
- void AddQueryBuffer(const CString& sFormat, const CString& sText = "") { m_QueryBuffer.AddLine(sFormat, sText); }
- void UpdateQueryBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_QueryBuffer.UpdateLine(sMatch, sFormat, sText); }
- void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
+ void AddNoticeBuffer(const CString& sFormat, const CString& sText = "") { m_NoticeBuffer.AddLine(sFormat, sText); }
+ void UpdateNoticeBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_NoticeBuffer.UpdateLine(sMatch, sFormat, sText); }
+ void ClearNoticeBuffer() { m_NoticeBuffer.Clear(); }
// !Buffers
// la
@@ -192,6 +199,7 @@ class CIRCNetwork {
CIRCSock* m_pIRCSock;
std::vector<CChan*> m_vChans;
+ std::vector<CQuery*> m_vQueries;
CString m_sChanPrefixes;
@@ -208,7 +216,7 @@ class CIRCNetwork {
CBuffer m_RawBuffer;
CBuffer m_MotdBuffer;
- CBuffer m_QueryBuffer;
+ CBuffer m_NoticeBuffer;
CIRCNetworkPingTimer* m_pPingTimer;
CIRCNetworkJoinTimer* m_pJoinTimer;
View
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2004-2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _QUERY_H
+#define _QUERY_H
+
+#include <znc/zncconfig.h>
+#include <znc/ZNCString.h>
+#include <znc/Buffer.h>
+
+// Forward Declarations
+class CClient;
+class CIRCNetwork;
+// !Forward Declarations
+
+class CQuery {
+public:
+ CQuery(const CString& sName, CIRCNetwork* pNetwork);
+ ~CQuery();
+
+ // Buffer
+ const CBuffer& GetBuffer() const { return m_Buffer; }
+ unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
+ bool SetBufferCount(unsigned int u, bool bForce = false) { return m_Buffer.SetLineCount(u, bForce); }
+ size_t AddBuffer(const CString& sFormat, const CString& sText = "", const timeval* ts = NULL) { return m_Buffer.AddLine(sFormat, sText, ts); }
+ void ClearBuffer() { m_Buffer.Clear(); }
+ void SendBuffer(CClient* pClient);
+ void SendBuffer(CClient* pClient, const CBuffer& Buffer);
+ // !Buffer
+
+ // Getters
+ const CString& GetName() const { return m_sName; }
+ // !Getters
+
+private:
+ CString m_sName;
+ CIRCNetwork* m_pNetwork;
+ CBuffer m_Buffer;
+};
+
+#endif // !_QUERY_H
View
@@ -126,6 +126,7 @@ class CUser {
bool DelCTCPReply(const CString& sCTCP);
bool SetBufferCount(unsigned int u, bool bForce = false);
void SetAutoClearChanBuffer(bool b);
+ void SetAutoClearQueryBuffer(bool b);
void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
void SetTimestampFormat(const CString& s) { m_sTimestampFormat = s; }
@@ -136,6 +137,7 @@ class CUser {
void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
void SetSkinName(const CString& s) { m_sSkinName = s; }
void SetMaxNetworks(unsigned int i) { m_uMaxNetworks = i; }
+ void SetMaxQueryBuffers(unsigned int i) { m_uMaxQueryBuffers = i; }
// !Setters
// Getters
@@ -171,6 +173,7 @@ class CUser {
const MCString& GetCTCPReplies() const;
unsigned int GetBufferCount() const;
bool AutoClearChanBuffer() const;
+ bool AutoClearQueryBuffer() const;
bool IsBeingDeleted() const { return m_bBeingDeleted; }
CString GetTimezone() const { return m_sTimezone; }
unsigned long long BytesRead() const { return m_uBytesRead; }
@@ -179,6 +182,7 @@ class CUser {
unsigned int MaxJoins() const { return m_uMaxJoins; }
CString GetSkinName() const;
unsigned int MaxNetworks() const { return m_uMaxNetworks; }
+ unsigned int MaxQueryBuffers() const { return m_uMaxQueryBuffers; }
// !Getters
protected:
@@ -211,6 +215,7 @@ class CUser {
bool m_bAdmin;
bool m_bDenySetBindHost;
bool m_bAutoClearChanBuffer;
+ bool m_bAutoClearQueryBuffer;
bool m_bBeingDeleted;
bool m_bAppendTimestamp;
bool m_bPrependTimestamp;
@@ -225,6 +230,7 @@ class CUser {
unsigned long long m_uBytesWritten;
unsigned int m_uMaxJoinTries;
unsigned int m_uMaxNetworks;
+ unsigned int m_uMaxQueryBuffers;
unsigned int m_uMaxJoins;
CString m_sSkinName;
@@ -16,6 +16,7 @@
#include <znc/IRCNetwork.h>
#include <znc/Chan.h>
+#include <znc/Query.h>
using std::vector;
@@ -26,9 +27,8 @@ class CClearBufferOnMsgMod : public CModule {
void ClearAllBuffers() {
if (m_pNetwork) {
const vector<CChan*>& vChans = m_pNetwork->GetChans();
- vector<CChan*>::const_iterator it;
- for (it = vChans.begin(); it != vChans.end(); ++it) {
+ for (vector<CChan*>::const_iterator it = vChans.begin(); it != vChans.end(); ++it) {
// Skip detached channels, they weren't read yet
if ((*it)->IsDetached())
continue;
@@ -38,6 +38,12 @@ class CClearBufferOnMsgMod : public CModule {
// doesn't make any sense with it
(*it)->SetAutoClearChanBuffer(false);
}
+
+ vector<CQuery*> VQueries = m_pNetwork->GetQueries();
+
+ for (vector<CQuery*>::const_iterator it = VQueries.begin(); it != VQueries.end(); ++it) {
+ m_pNetwork->DelQuery((*it)->GetName());
+ }
}
}
@@ -76,4 +82,4 @@ template<> void TModInfo<CClearBufferOnMsgMod>(CModInfo& Info) {
Info.SetWikiPage("clearbufferonmsg");
}
-USERMODULEDEFS(CClearBufferOnMsgMod, "Clear all channel buffers whenever the user does something")
+USERMODULEDEFS(CClearBufferOnMsgMod, "Clear all channel and query buffers whenever the user does something")
View
@@ -65,10 +65,12 @@ class CAdminMod : public CModule {
{"QuitMsg", str},
{"BufferCount", integer},
{"AutoClearChanBuffer", boolean},
+ {"AutoClearQueryBuffer",boolean},
{"Password", str},
{"JoinTries", integer},
{"MaxJoins", integer},
{"MaxNetworks", integer},
+ {"MaxQueryBuffers", integer},
{"Timezone", str},
{"Admin", boolean},
{"AppendTimestamp", boolean},
@@ -194,10 +196,14 @@ class CAdminMod : public CModule {
PutModule("KeepBuffer = " + CString(!pUser->AutoClearChanBuffer())); // XXX compatibility crap, added in 0.207
else if (sVar == "autoclearchanbuffer")
PutModule("AutoClearChanBuffer = " + CString(pUser->AutoClearChanBuffer()));
+ else if (sVar == "autoclearquerybuffer")
+ PutModule("AutoClearQueryBuffer = " + CString(pUser->AutoClearQueryBuffer()));
else if (sVar == "maxjoins")
PutModule("MaxJoins = " + CString(pUser->MaxJoins()));
else if (sVar == "maxnetworks")
PutModule("MaxNetworks = " + CString(pUser->MaxNetworks()));
+ else if (sVar == "maxquerybuffers")
+ PutModule("MaxQueryBuffers = " + CString(pUser->MaxQueryBuffers()));
else if (sVar == "jointries")
PutModule("JoinTries = " + CString(pUser->JoinTries()));
else if (sVar == "timezone")
@@ -334,6 +340,11 @@ class CAdminMod : public CModule {
pUser->SetAutoClearChanBuffer(b);
PutModule("AutoClearChanBuffer = " + CString(b));
}
+ else if (sVar == "autoclearquerybuffer") {
+ bool b = sValue.ToBool();
+ pUser->SetAutoClearQueryBuffer(b);
+ PutModule("AutoClearQueryBuffer = " + CString(b));
+ }
else if (sVar == "password") {
const CString sSalt = CUtils::GetSalt();
const CString sHash = CUser::SaltedHash(sValue, sSalt);
@@ -354,6 +365,11 @@ class CAdminMod : public CModule {
PutModule("Access denied!");
}
}
+ else if (sVar == "maxquerybuffers") {
+ unsigned int i = sValue.ToUInt();
+ pUser->SetMaxQueryBuffers(i);
+ PutModule("MaxQueryBuffers = " + sValue);
+ }
else if (sVar == "jointries") {
unsigned int i = sValue.ToUInt();
pUser->SetJoinTries(i);
@@ -226,11 +226,11 @@
</div>
<div class="section">
- <h3>Default Settings For New Future Channels</h3>
+ <h3>Default Settings</h3>
<div class="sectionbg">
<div class="sectionbody">
<div class="subsection third">
- <div class="inputlabel">Modes:</div>
+ <div class="inputlabel">Channel Modes:</div>
<input type="text" name="chanmodes" value="<? VAR DefaultChanModes ?>" maxlength="32"
title="These are the default modes ZNC will set when you join an empty channel." />
<br /><span class="info">Empty = use standard value</span>
@@ -296,6 +296,11 @@
<input type="number" name="maxnetworks" value="<? VAR MaxNetworks ?>" class="third" min="0"
title="Maximum number of IRC networks allowed for this user." <? IF !ImAdmin ?>disabled="disabled"<? ENDIF ?> />
</div>
+ <div class="subsection">
+ <div class="inputlabel">Max Query Buffers:</div>
+ <input type="number" name="maxquerybuffers" value="<? VAR MaxQueryBuffers ?>" class="third" min="0"
+ title="Maximum number of query buffers. 0 is unlimited."/>
+ </div>
<div class="subsection half">
<div class="inputlabel">CTCP Replies:</div>
<div><textarea name="ctcpreplies" cols="70" rows="3"><? LOOP CTCPLoop ?><? VAR CTCP ?>
Oops, something went wrong.

0 comments on commit 83a25c5

Please sign in to comment.