From 848085db68accd7d00c511445cfd42406660e6e0 Mon Sep 17 00:00:00 2001 From: Mikaela Suomalainen Date: Thu, 19 Feb 2015 08:08:35 +0200 Subject: [PATCH 1/6] sasl: fix help text for requireauth Closes #875 --- modules/sasl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sasl.cpp b/modules/sasl.cpp index e6b60a88..ad631cf4 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -74,7 +74,7 @@ public: AddCommand("Mechanism", static_cast(&CSASLMod::SetMechanismCommand), "[mechanism[ ...]]", "Set the mechanisms to be attempted (in order)"); AddCommand("RequireAuth", static_cast(&CSASLMod::RequireAuthCommand), - "[yes|no]", "Don't connect if SASL cannot be authenticated"); + "[yes|no]", "Don't connect unless SASL authentication succeeds"); m_bAuthenticated = false; } From ac3570f18a870673dbfb9fbeccac8fb28f0150c1 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Tue, 17 Feb 2015 10:08:30 +0000 Subject: [PATCH 2/6] fix savebuff timer initialization closes #868 --- modules/savebuff.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index 0a95e8e3..af20a0af 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -93,13 +93,13 @@ public: else m_sPassword = CBlowfish::MD5(sArgs); + AddTimer(new CSaveBuffJob(this, 60, 0, "SaveBuff", "Saves the current buffer to disk every 1 minute")); + return( !m_bBootError ); } virtual bool OnBoot() override { - AddTimer(new CSaveBuffJob(this, 60, 0, "SaveBuff", "Saves the current buffer to disk every 1 minute")); - CDir saveDir(GetSavePath()); for (CFile* pFile : saveDir) { CString sName; From fd34f84bfd886237d1b0f564c874054a91fed7d6 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 14 Feb 2015 19:41:26 +0100 Subject: [PATCH 3/6] ~CThreadPool(): Handle spurious wakeups From pthread_cond_wait()'s man page: When using condition variables there is always a boolean predicate involving shared variables associated with each condition wait that is true if the thread should proceed. Spurious wakeups from the pthread_cond_wait() or pthread_cond_timedwait() functions may occur. Since the return from pthread_cond_wait() or pthread_cond_timedwait() does not imply anything about the value of this predicate, the predicate should be re-evaluated upon such return. Fix ~CThreadPool() to account for this possibility. Signed-off-by: Uli Schlachter --- src/Threads.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Threads.cpp b/src/Threads.cpp index c2e6bf2d..c6d28a9e 100644 --- a/src/Threads.cpp +++ b/src/Threads.cpp @@ -87,7 +87,7 @@ CThreadPool::~CThreadPool() { CMutexLocker guard(m_mutex); m_done = true; - if (m_num_threads > 0) { + while (m_num_threads > 0) { m_cond.broadcast(); m_exit_cond.wait(m_mutex); } From 5f9ad5cc87cb4f5cc987b7c43d2d19a36937e53f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 15 Feb 2015 09:31:01 +0100 Subject: [PATCH 4/6] SSLVerifyHost: Make some functions static These functions shouldn't be visible outside of this file. This was caught by -Werror=missing-declarations. Signed-off-by: Uli Schlachter --- src/SSLVerifyHost.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SSLVerifyHost.cpp b/src/SSLVerifyHost.cpp index c9bce282..2b5af5ef 100644 --- a/src/SSLVerifyHost.cpp +++ b/src/SSLVerifyHost.cpp @@ -119,7 +119,7 @@ inline char Curl_raw_toupper(char in) * The function is capable of comparing a-z case insensitively even for * non-ascii. */ -int Curl_raw_equal(const char *first, const char *second) +static int Curl_raw_equal(const char *first, const char *second) { while(*first && *second) { if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) @@ -133,7 +133,7 @@ int Curl_raw_equal(const char *first, const char *second) return this as a successful match */ return (Curl_raw_toupper(*first) == Curl_raw_toupper(*second)); } -int Curl_raw_nequal(const char *first, const char *second, size_t max) +static int Curl_raw_nequal(const char *first, const char *second, size_t max) { while(*first && *second && max) { if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) { @@ -234,7 +234,7 @@ static int hostmatch(char *hostname, char *pattern) CURL_HOST_MATCH : CURL_HOST_NOMATCH; } -int Curl_cert_hostcheck(const char *match_pattern, const char *hostname) +static int Curl_cert_hostcheck(const char *match_pattern, const char *hostname) { char *matchp; char *hostp; From 7345a6ee3ac8547da46e6906843937f8e43aed80 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 3 Feb 2015 10:11:47 +0100 Subject: [PATCH 5/6] Fix CIRCNetwork::FindChans() and FindQueries() to be case-insensitive The playback module failed to clear a buffer, because it tried to clear "NickServ" whereas ZNC had internally stored it has "nickserv". --- Makefile.in | 2 +- src/IRCNetwork.cpp | 6 ++- test/NetworkTest.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 test/NetworkTest.cpp diff --git a/Makefile.in b/Makefile.in index 2819b2c4..4a5b521b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -48,7 +48,7 @@ LIB_SRCS := $(addprefix src/,$(LIB_SRCS)) BIN_SRCS := src/main.cpp LIB_OBJS := $(patsubst %cpp,%o,$(LIB_SRCS)) BIN_OBJS := $(patsubst %cpp,%o,$(BIN_SRCS)) -TESTS := StringTest ConfigTest UtilsTest ThreadTest NickTest ClientTest +TESTS := StringTest ConfigTest UtilsTest ThreadTest NickTest ClientTest NetworkTest TESTS := $(addprefix test/,$(addsuffix .o,$(TESTS))) CLEAN := znc src/*.o test/*.o core core.* .version_extra .depend modules/.depend unittest DISTCLEAN := Makefile config.log config.status znc-buildmod include/znc/zncconfig.h \ diff --git a/src/IRCNetwork.cpp b/src/IRCNetwork.cpp index 916c7878..d97e10b5 100644 --- a/src/IRCNetwork.cpp +++ b/src/IRCNetwork.cpp @@ -787,8 +787,9 @@ CChan* CIRCNetwork::FindChan(CString sName) const { std::vector CIRCNetwork::FindChans(const CString& sWild) const { std::vector vChans; vChans.reserve(m_vChans.size()); + const CString sLower = sWild.AsLower(); for (std::vector::const_iterator it = m_vChans.begin(); it != m_vChans.end(); ++it) { - if ((*it)->GetName().WildCmp(sWild)) + if ((*it)->GetName().AsLower().WildCmp(sLower)) vChans.push_back(*it); } return vChans; @@ -946,8 +947,9 @@ CQuery* CIRCNetwork::FindQuery(const CString& sName) const { std::vector CIRCNetwork::FindQueries(const CString& sWild) const { std::vector vQueries; vQueries.reserve(m_vQueries.size()); + const CString sLower = sWild.AsLower(); for (std::vector::const_iterator it = m_vQueries.begin(); it != m_vQueries.end(); ++it) { - if ((*it)->GetName().WildCmp(sWild)) + if ((*it)->GetName().AsLower().WildCmp(sLower)) vQueries.push_back(*it); } return vQueries; diff --git a/test/NetworkTest.cpp b/test/NetworkTest.cpp new file mode 100644 index 00000000..bbeca6c8 --- /dev/null +++ b/test/NetworkTest.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2004-2015 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. + */ + +#include +#include +#include +#include + +class NetworkTest : public ::testing::Test { +protected: + void SetUp() { CZNC::CreateInstance(); } + void TearDown() { CZNC::DestroyInstance(); } +}; + +TEST_F(NetworkTest, FindChan) { + CUser user("user"); + CIRCNetwork network(&user, "network"); + + EXPECT_TRUE(network.AddChan("#foo", false)); + EXPECT_TRUE(network.AddChan("#Bar", false)); + EXPECT_TRUE(network.AddChan("#BAZ", false)); + + EXPECT_TRUE(network.FindChan("#foo")); + EXPECT_TRUE(network.FindChan("#Bar")); + EXPECT_TRUE(network.FindChan("#BAZ")); + + EXPECT_TRUE(network.FindChan("#Foo")); + EXPECT_TRUE(network.FindChan("#BAR")); + EXPECT_TRUE(network.FindChan("#baz")); + + EXPECT_FALSE(network.FindChan("#f")); + EXPECT_FALSE(network.FindChan("&foo")); + EXPECT_FALSE(network.FindChan("##foo")); +} + +TEST_F(NetworkTest, FindChans) { + CUser user("user"); + CIRCNetwork network(&user, "network"); + + EXPECT_TRUE(network.AddChan("#foo", false)); + EXPECT_TRUE(network.AddChan("#Bar", false)); + EXPECT_TRUE(network.AddChan("#BAZ", false)); + + EXPECT_EQ(network.FindChans("#f*").size(), 1); + EXPECT_EQ(network.FindChans("#b*").size(), 2); + EXPECT_EQ(network.FindChans("#?A*").size(), 2); + EXPECT_EQ(network.FindChans("*z").size(), 1); +} + +TEST_F(NetworkTest, FindQuery) { + CUser user("user"); + CIRCNetwork network(&user, "network"); + + EXPECT_TRUE(network.AddQuery("foo")); + EXPECT_TRUE(network.AddQuery("Bar")); + EXPECT_TRUE(network.AddQuery("BAZ")); + + EXPECT_TRUE(network.FindQuery("foo")); + EXPECT_TRUE(network.FindQuery("Bar")); + EXPECT_TRUE(network.FindQuery("BAZ")); + + EXPECT_TRUE(network.FindQuery("Foo")); + EXPECT_TRUE(network.FindQuery("BAR")); + EXPECT_TRUE(network.FindQuery("baz")); + + EXPECT_FALSE(network.FindQuery("f")); + EXPECT_FALSE(network.FindQuery("fo")); + EXPECT_FALSE(network.FindQuery("FF")); +} + +TEST_F(NetworkTest, FindQueries) { + CUser user("user"); + CIRCNetwork network(&user, "network"); + + EXPECT_TRUE(network.AddQuery("foo")); + EXPECT_TRUE(network.AddQuery("Bar")); + EXPECT_TRUE(network.AddQuery("BAZ")); + + EXPECT_EQ(network.FindQueries("f*").size(), 1); + EXPECT_EQ(network.FindQueries("b*").size(), 2); + EXPECT_EQ(network.FindQueries("?A*").size(), 2); + EXPECT_EQ(network.FindQueries("*z").size(), 1); +} From 2082362b0bcfd5a25ba921725d48601e44005cba Mon Sep 17 00:00:00 2001 From: Mikaela Suomalainen Date: Thu, 19 Feb 2015 08:12:58 +0200 Subject: [PATCH 6/6] modules/sasl.cpp: update help for "set" This is the same as #793, but for correct branch. Closes #793 --- modules/sasl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/sasl.cpp b/modules/sasl.cpp index e6b60a88..e8a07005 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -70,7 +70,7 @@ public: AddCommand("Help", static_cast(&CSASLMod::PrintHelp), "search", "Generate this output"); AddCommand("Set", static_cast(&CSASLMod::Set), - "username password", "Set username and password for the PLAIN mechanism"); + " []", "Set username and password for the mechanisms that need them. Password is optional"); AddCommand("Mechanism", static_cast(&CSASLMod::SetMechanismCommand), "[mechanism[ ...]]", "Set the mechanisms to be attempted (in order)"); AddCommand("RequireAuth", static_cast(&CSASLMod::RequireAuthCommand),