summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_mysql.cpp2
-rw-r--r--src/modules/extra/m_regex_stdlib.cpp112
-rw-r--r--src/modules/m_blockamsg.cpp6
-rw-r--r--src/modules/m_cgiirc.cpp61
-rw-r--r--src/modules/m_dnsbl.cpp6
-rw-r--r--src/modules/m_knock.cpp32
-rw-r--r--src/modules/m_shun.cpp1
-rw-r--r--src/modules/m_sslinfo.cpp4
8 files changed, 177 insertions, 47 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp
index 86d9273c3..570e7d9ec 100644
--- a/src/modules/extra/m_mysql.cpp
+++ b/src/modules/extra/m_mysql.cpp
@@ -503,7 +503,7 @@ void DispatcherThread::Run()
*/
this->LockQueue();
- if (Parent->qq.front().q == i.q)
+ if (!Parent->qq.empty() && Parent->qq.front().q == i.q)
{
Parent->qq.pop_front();
Parent->rq.push_back(RQueueItem(i.q, res));
diff --git a/src/modules/extra/m_regex_stdlib.cpp b/src/modules/extra/m_regex_stdlib.cpp
new file mode 100644
index 000000000..4942e9739
--- /dev/null
+++ b/src/modules/extra/m_regex_stdlib.cpp
@@ -0,0 +1,112 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2012 ChrisTX <chris@rev-crew.info>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "inspircd.h"
+#include "m_regex.h"
+#include <regex>
+
+/* $ModDesc: Regex Provider Module for std::regex Regular Expressions */
+/* $ModConfig: <stdregex type="ecmascript">
+ * Specify the Regular Expression engine to use here. Valid settings are
+ * bre, ere, awk, grep, egrep, ecmascript (default if not specified)*/
+/* $CompileFlags: -std=c++11 */
+/* $ModDep: m_regex.h */
+
+class StdRegexException : public ModuleException
+{
+public:
+ StdRegexException(const std::string& rx, const std::string& error)
+ : ModuleException(std::string("Error in regex ") + rx + ": " + error)
+ {
+ }
+};
+
+class StdRegex : public Regex
+{
+private:
+ std::regex regexcl;
+public:
+ StdRegex(const std::string& rx, std::regex::flag_type fltype) : Regex(rx)
+ {
+ try{
+ regexcl.assign(rx, fltype | std::regex::optimize);
+ }
+ catch(std::regex_error rxerr)
+ {
+ throw StdRegexException(rx, rxerr.what());
+ }
+ }
+
+ virtual bool Matches(const std::string& text)
+ {
+ return std::regex_search(text, regexcl);
+ }
+};
+
+class StdRegexFactory : public RegexFactory
+{
+ public:
+ std::regex::flag_type regextype;
+ StdRegexFactory(Module* m) : RegexFactory(m, "regex/stdregex") {}
+ Regex* Create(const std::string& expr)
+ {
+ return new StdRegex(expr, regextype);
+ }
+};
+
+class ModuleRegexStd : public Module
+{
+public:
+ StdRegexFactory ref;
+ ModuleRegexStd() : ref(this) {
+ ServerInstance->Modules->AddService(ref);
+ Implementation eventlist[] = { I_OnRehash };
+ ServerInstance->Modules->Attach(eventlist, this, 1);
+ OnRehash(NULL);
+ }
+
+ Version GetVersion()
+ {
+ return Version("Regex Provider Module for std::regex", VF_VENDOR);
+ }
+
+ void OnRehash(User* u)
+ {
+ ConfigTag* Conf = ServerInstance->Config->ConfValue("stdregex");
+ std::string regextype = Conf->getString("type", "ecmascript");
+
+ if(regextype == "bre")
+ ref.regextype = std::regex::basic;
+ else if(regextype == "ere")
+ ref.regextype = std::regex::extended;
+ else if(regextype == "awk")
+ ref.regextype = std::regex::awk;
+ else if(regextype == "grep")
+ ref.regextype = std::regex::grep;
+ else if(regextype == "egrep")
+ ref.regextype = std::regex::egrep;
+ else
+ {
+ if(regextype != "ecmascript")
+ ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Non-existent regex engine '%s' specified. Falling back to ECMAScript.", regextype.c_str());
+ ref.regextype = std::regex::ECMAScript;
+ }
+ }
+};
+
+MODULE_INIT(ModuleRegexStd)
diff --git a/src/modules/m_blockamsg.cpp b/src/modules/m_blockamsg.cpp
index 8160fcf54..c570e0a71 100644
--- a/src/modules/m_blockamsg.cpp
+++ b/src/modules/m_blockamsg.cpp
@@ -102,11 +102,7 @@ class ModuleBlockAmsg : public Module
if (user->registered != REG_ALL)
return MOD_RES_PASSTHRU;
- // We want case insensitive command comparison.
- // Add std::string contructor for irc::string :x
- irc::string cmd = command.c_str();
-
- if(validated && (cmd == "PRIVMSG" || cmd == "NOTICE") && (parameters.size() >= 2))
+ if ((validated) && (parameters.size() >= 2) && ((command == "PRIVMSG") || (command == "NOTICE")))
{
// parameters[0] should have the target(s) in it.
// I think it will be faster to first check if there are any commas, and if there are then try and parse it out.
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index 330c1b6c4..f47dc4b53 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -181,16 +181,10 @@ public:
ServerInstance->Extensions.Register(&cmd.realip);
ServerInstance->Extensions.Register(&cmd.webirc_hostname);
ServerInstance->Extensions.Register(&cmd.webirc_ip);
+ ServerInstance->Extensions.Register(&waiting);
- Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCheckReady, I_OnUserConnect };
- ServerInstance->Modules->Attach(eventlist, this, 4);
- }
-
- void Prioritize()
- {
- ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_FIRST);
- Module* umodes = ServerInstance->Modules->Find("m_conn_umodes.so");
- ServerInstance->Modules->SetPriority(this, I_OnUserConnect, PRIORITY_BEFORE, &umodes);
+ Implementation eventlist[] = { I_OnRehash, I_OnUserRegister, I_OnCheckReady };
+ ServerInstance->Modules->Attach(eventlist, this, 3);
}
void OnRehash(User* user)
@@ -245,6 +239,32 @@ public:
{
if (waiting.get(user))
return MOD_RES_DENY;
+
+ std::string *webirc_ip = cmd.webirc_ip.get(user);
+ if (!webirc_ip)
+ return MOD_RES_PASSTHRU;
+
+ ServerInstance->Users->RemoveCloneCounts(user);
+ user->SetClientIP(webirc_ip->c_str());
+ cmd.webirc_ip.unset(user);
+
+ std::string* webirc_hostname = cmd.webirc_hostname.get(user);
+ if (webirc_hostname && webirc_hostname->length() < 64)
+ user->host = user->dhost = *webirc_hostname;
+ else
+ user->host = user->dhost = user->GetIPString();
+
+ user->InvalidateCache();
+ cmd.webirc_hostname.unset(user);
+
+ ServerInstance->Users->AddLocalClone(user);
+ ServerInstance->Users->AddGlobalClone(user);
+ user->SetClass();
+ user->CheckClass();
+ user->CheckLines(true);
+ if (user->quitting)
+ return MOD_RES_DENY;
+
return MOD_RES_PASSTHRU;
}
@@ -287,29 +307,6 @@ public:
return MOD_RES_PASSTHRU;
}
- virtual void OnUserConnect(LocalUser* user)
- {
- std::string *webirc_hostname = cmd.webirc_hostname.get(user);
- std::string *webirc_ip = cmd.webirc_ip.get(user);
- if (!webirc_ip)
- return;
- ServerInstance->Users->RemoveCloneCounts(user);
- user->SetClientIP(webirc_ip->c_str());
- user->InvalidateCache();
- if (webirc_hostname && webirc_hostname->length() < 64)
- user->host = user->dhost = *webirc_hostname;
- else
- user->host = user->dhost = user->GetIPString();
- user->InvalidateCache();
- ServerInstance->Users->AddLocalClone(user);
- ServerInstance->Users->AddGlobalClone(user);
- user->SetClass();
- user->CheckClass();
- user->CheckLines(true);
- cmd.webirc_ip.unset(user);
- cmd.webirc_hostname.unset(user);
- }
-
bool CheckPass(LocalUser* user)
{
if(IsValidHost(user->password))
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index 2160b02dc..645949006 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -185,7 +185,7 @@ class DNSBLResolver : public Resolver
break;
}
- ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s detected as being on a DNS blacklist (%s) with result %d", them->GetFullRealHost().c_str(), ConfEntry->domain.c_str(), (ConfEntry->type==DNSBLConfEntry::A_BITMASK) ? bitmask : record);
+ ServerInstance->SNO->WriteGlobalSno('a', "Connecting user %s%s detected as being on a DNS blacklist (%s) with result %d", them->nick.empty() ? "<unknown>" : "", them->GetFullRealHost().c_str(), ConfEntry->domain.c_str(), (ConfEntry->type==DNSBLConfEntry::A_BITMASK) ? bitmask : record);
}
else
ConfEntry->stats_misses++;
@@ -243,7 +243,7 @@ class ModuleDNSBL : public Module
ReadConf();
ServerInstance->Modules->AddService(nameExt);
ServerInstance->Modules->AddService(countExt);
- Implementation eventlist[] = { I_OnRehash, I_OnUserInit, I_OnStats, I_OnSetConnectClass, I_OnCheckReady };
+ Implementation eventlist[] = { I_OnRehash, I_OnSetUserIP, I_OnStats, I_OnSetConnectClass, I_OnCheckReady };
ServerInstance->Modules->Attach(eventlist, this, 5);
}
@@ -348,7 +348,7 @@ class ModuleDNSBL : public Module
ReadConf();
}
- void OnUserInit(LocalUser* user)
+ void OnSetUserIP(LocalUser* user)
{
if (user->exempt)
return;
diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp
index 8cd5088bc..97eb0e005 100644
--- a/src/modules/m_knock.cpp
+++ b/src/modules/m_knock.cpp
@@ -28,6 +28,8 @@
class CommandKnock : public Command
{
public:
+ bool sendnotice;
+ bool sendnumeric;
CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2, 2)
{
syntax = "<channel> <reason>";
@@ -62,7 +64,12 @@ class CommandKnock : public Command
return CMD_FAILURE;
}
- c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), parameters[1].c_str());
+ if (sendnotice)
+ c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), parameters[1].c_str());
+
+ if (sendnumeric)
+ c->WriteChannelWithServ(ServerInstance->Config->ServerName, "710 %s %s %s :is KNOCKing: %s", c->name.c_str(), c->name.c_str(), user->GetFullHost().c_str(), parameters[1].c_str());
+
user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str());
return CMD_SUCCESS;
}
@@ -92,11 +99,30 @@ class ModuleKnock : public Module
throw ModuleException("Could not add new modes!");
ServerInstance->AddCommand(&cmd);
+ ServerInstance->Modules->Attach(I_OnRehash, this);
+ OnRehash(NULL);
}
-
- virtual ~ModuleKnock()
+ void OnRehash(User* user)
{
+ std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
+ irc::string notify(knocknotify.c_str());
+
+ if (notify == "numeric")
+ {
+ cmd.sendnotice = false;
+ cmd.sendnumeric = true;
+ }
+ else if (notify == "both")
+ {
+ cmd.sendnotice = true;
+ cmd.sendnumeric = true;
+ }
+ else
+ {
+ cmd.sendnotice = true;
+ cmd.sendnumeric = false;
+ }
}
virtual Version GetVersion()
diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp
index 197bbc1bf..78046954c 100644
--- a/src/modules/m_shun.cpp
+++ b/src/modules/m_shun.cpp
@@ -215,6 +215,7 @@ class ModuleShun : public Module
{
ConfigReader MyConf;
std::string cmds = MyConf.ReadValue("shun", "enabledcommands", 0);
+ std::transform(cmds.begin(), cmds.end(), cmds.begin(), ::toupper);
if (cmds.empty())
cmds = "PING PONG QUIT";
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index 22be27383..33a36d3b4 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -174,9 +174,7 @@ class ModuleSSLInfo : public Module
ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
{
- irc::string pcmd = command.c_str();
-
- if ((pcmd == "OPER") && (validated))
+ if ((command == "OPER") && (validated))
{
OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
if (i != ServerInstance->Config->oper_blocks.end())