2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2016, 2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
8 * Copyright (C) 2011 Adam <Adam@anope.org>
9 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
11 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /// $CompilerFlags: execute("pcre-config --cflags" "PCRE_CXXFLAGS")
27 /// $LinkerFlags: execute("pcre-config --libs" "PCRE_LDFLAGS" "-lpcre")
29 /// $PackageInfo: require_system("arch") pcre
30 /// $PackageInfo: require_system("centos") pcre-devel
31 /// $PackageInfo: require_system("darwin") pcre
32 /// $PackageInfo: require_system("debian") libpcre3-dev
33 /// $PackageInfo: require_system("ubuntu") libpcre3-dev
38 #include "modules/regex.h"
41 # pragma comment(lib, "libpcre.lib")
44 class PCRERegex : public Regex
49 PCRERegex(const std::string& rx) : Regex(rx)
53 regex = pcre_compile(rx.c_str(), 0, &error, &erroffset, NULL);
56 ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "pcre_compile failed: /%s/ [%d] %s", rx.c_str(), erroffset, error);
57 throw RegexException(rx, error, erroffset);
66 bool Matches(const std::string& text) CXX11_OVERRIDE
68 return (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) >= 0);
72 class PCREFactory : public RegexFactory
75 PCREFactory(Module* m) : RegexFactory(m, "regex/pcre") {}
76 Regex* Create(const std::string& expr) CXX11_OVERRIDE
78 return new PCRERegex(expr);
82 class ModuleRegexPCRE : public Module
86 ModuleRegexPCRE() : ref(this)
90 Version GetVersion() CXX11_OVERRIDE
92 return Version("Provides a regular expression engine which uses the PCRE library.", VF_VENDOR);
96 MODULE_INIT(ModuleRegexPCRE)