/* * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013, 2021 Sadie Powell * Copyright (C) 2012-2013 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2008 Thomas Stagner * * 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 . */ #include "inspircd.h" #include "modules/regex.h" #include #include class POSIXPattern final : public Regex::Pattern { private: regex_t regex; public: POSIXPattern(const Module* mod, const std::string& pattern, uint8_t options) : Regex::Pattern(pattern, options) { int flags = REG_EXTENDED | REG_NOSUB; if (options & Regex::OPT_CASE_INSENSITIVE) flags &= REG_ICASE; int error = regcomp(®ex, pattern.c_str(), flags); if (!error) return; // Retrieve the size of the error message and allocate a buffer. size_t errorsize = regerror(error, ®ex, NULL, 0); std::vector errormsg(errorsize); // Retrieve the error message and free the buffer. regerror(error, ®ex, &errormsg[0], errormsg.size()); regfree(®ex); throw Regex::Exception(mod, pattern, std::string(&errormsg[0], errormsg.size())); } ~POSIXPattern() override { regfree(®ex); } bool IsMatch(const std::string& text) override { return !regexec(®ex, text.c_str(), 0, NULL, 0); } }; class ModuleRegexPOSIX final : public Module { private: Regex::SimpleEngine regex; public: ModuleRegexPOSIX() : Module(VF_VENDOR, "Provides the posix regular expression engine which uses the POSIX.2 regular expression matching system.") , regex(this, "posix") { } }; MODULE_INIT(ModuleRegexPOSIX)