mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 10:39:02 -04:00
Import regex_pcre2 from inspircd-contrib.
The original plan was to make the PCRE2 switch happen in v3 but it seems that distributions are beginning to unpackage the old pcre library already.
This commit is contained in:
parent
1203f3ae15
commit
0a03eada1c
3
.github/workflows/ci-alpine.yml
vendored
3
.github/workflows/ci-alpine.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CXXFLAGS: -std=${{ matrix.standard }}
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_pcre2 regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@ -33,6 +33,7 @@ jobs:
|
||||
openldap-dev \
|
||||
openssl-dev \
|
||||
pcre-dev \
|
||||
pcre2-dev \
|
||||
perl \
|
||||
pkgconf \
|
||||
re2-dev \
|
||||
|
3
.github/workflows/ci-linux.yml
vendored
3
.github/workflows/ci-linux.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CXXFLAGS: -std=${{ matrix.standard }}
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_pcre2 regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
@ -27,6 +27,7 @@ jobs:
|
||||
libmaxminddb-dev \
|
||||
libmbedtls-dev \
|
||||
libmysqlclient-dev \
|
||||
libpcre2-dev \
|
||||
libpcre3-dev \
|
||||
libpq-dev \
|
||||
libre2-dev \
|
||||
|
4
.github/workflows/ci-macos.yml
vendored
4
.github/workflows/ci-macos.yml
vendored
@ -11,14 +11,14 @@ jobs:
|
||||
env:
|
||||
CXXFLAGS: -std=${{ matrix.standard }} -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
|
||||
HOMEBREW_NO_INSTALL_CLEANUP: 1
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
TEST_BUILD_MODULES: argon2 geo_maxmind ldap mysql pgsql regex_pcre regex_pcre2 regex_posix regex_re2 regex_stdlib regex_tre sqlite3 ssl_gnutls ssl_mbedtls ssl_openssl sslrehashsignal
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew update || true
|
||||
for PACKAGE in pkg-config argon2 gnutls libmaxminddb libpq mbedtls mysql-client openssl@3 openldap pcre re2 sqlite tre;
|
||||
for PACKAGE in pkg-config argon2 gnutls libmaxminddb libpq mbedtls mysql-client openssl@3 openldap pcre pcre2 re2 sqlite tre;
|
||||
do
|
||||
brew install $PACKAGE || brew upgrade $PACKAGE
|
||||
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@
|
||||
/src/modules/m_mysql.cpp
|
||||
/src/modules/m_pgsql.cpp
|
||||
/src/modules/m_regex_pcre.cpp
|
||||
/src/modules/m_regex_pcre2.cpp
|
||||
/src/modules/m_regex_posix.cpp
|
||||
/src/modules/m_regex_re2.cpp
|
||||
/src/modules/m_regex_stdlib.cpp
|
||||
|
1
configure
vendored
1
configure
vendored
@ -418,6 +418,7 @@ if (prompt_bool $interactive, $question, 0) {
|
||||
'm_pgsql.cpp' => 'pg_config --version',
|
||||
'm_ldap.cpp' => "echo '#include <ldap.h>' | $config{CXX} -E -",
|
||||
'm_regex_pcre.cpp' => 'pcre-config --version',
|
||||
'm_regex_pcre2.cpp' => 'pkg-config --exists libpcre2-8',
|
||||
'm_regex_posix.cpp' => undef,
|
||||
'm_regex_re2.cpp' => 'pkg-config --exists re2',
|
||||
'm_regex_stdlib.cpp' => "$config{CXX} -o /dev/null -std=c++11 $RealDir/make/test/compiler.cpp",
|
||||
|
@ -1868,6 +1868,13 @@
|
||||
# R-line modules.
|
||||
#<module name="regex_pcre">
|
||||
|
||||
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
||||
# Regular expression provider for PCRE2 (Perl-Compatible Regular
|
||||
# Expressions). You need libpcre2 installed to compile and load this
|
||||
# module. You must have at least 1 provider loaded to use the filter or
|
||||
# R-line modules.
|
||||
#<module name="regex_pcre2">
|
||||
|
||||
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
||||
# Regular Expression Provider for RE2 Regular Expressions.
|
||||
# You need libre2 installed and in your include/library paths in order
|
||||
|
108
src/modules/extra/m_regex_pcre2.cpp
Normal file
108
src/modules/extra/m_regex_pcre2.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* InspIRCd -- Internet Relay Chat Daemon
|
||||
*
|
||||
* Copyright (C) 2021 Sadie Powell <sadie@witchery.services>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
|
||||
/// $CompilerFlags: find_compiler_flags("libpcre2-8")
|
||||
/// $LinkerFlags: find_linker_flags("libpcre2-8")
|
||||
|
||||
/// $PackageInfo: require_system("arch") pcre2
|
||||
/// $PackageInfo: require_system("centos") pcre2-devel
|
||||
/// $PackageInfo: require_system("darwin") pcre2
|
||||
/// $PackageInfo: require_system("debian") libpcre2-dev
|
||||
/// $PackageInfo: require_system("ubuntu") libpcre2-dev
|
||||
|
||||
|
||||
#include "inspircd.h"
|
||||
#include "modules/regex.h"
|
||||
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#include <pcre2.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# pragma comment(lib, "pcre2-8.lib")
|
||||
#endif
|
||||
|
||||
class PCRE2Regex CXX11_FINAL
|
||||
: public Regex
|
||||
{
|
||||
private:
|
||||
pcre2_code* regex;
|
||||
|
||||
public:
|
||||
PCRE2Regex(const std::string& pattern)
|
||||
: Regex(pattern)
|
||||
{
|
||||
int errorcode;
|
||||
PCRE2_SIZE erroroffset;
|
||||
regex = pcre2_compile(reinterpret_cast<PCRE2_SPTR8>(pattern.c_str()), pattern.length(), 0, &errorcode, &erroroffset, NULL);
|
||||
if (!regex)
|
||||
{
|
||||
PCRE2_UCHAR errorstr[128];
|
||||
pcre2_get_error_message(errorcode, errorstr, sizeof errorstr);
|
||||
throw RegexException(pattern, reinterpret_cast<const char*>(errorstr), erroroffset);
|
||||
}
|
||||
}
|
||||
|
||||
~PCRE2Regex() CXX11_OVERRIDE
|
||||
{
|
||||
pcre2_code_free(regex);
|
||||
}
|
||||
|
||||
bool Matches(const std::string& text) CXX11_OVERRIDE
|
||||
{
|
||||
pcre2_match_data* unused = pcre2_match_data_create(1, NULL);
|
||||
int result = pcre2_match(regex, reinterpret_cast<PCRE2_SPTR8>(text.c_str()), text.length(), 0, 0, unused, NULL);
|
||||
pcre2_match_data_free(unused);
|
||||
return result >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
class PCRE2Factory CXX11_FINAL
|
||||
: public RegexFactory
|
||||
{
|
||||
public:
|
||||
PCRE2Factory(Module* Creator)
|
||||
: RegexFactory(Creator, "regex/pcre")
|
||||
{
|
||||
}
|
||||
|
||||
Regex* Create(const std::string& pattern) CXX11_OVERRIDE
|
||||
{
|
||||
return new PCRE2Regex(pattern);
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleRegexPCRE2 CXX11_FINAL
|
||||
: public Module
|
||||
{
|
||||
private:
|
||||
PCRE2Factory regex;
|
||||
|
||||
public:
|
||||
ModuleRegexPCRE2()
|
||||
: regex(this)
|
||||
{
|
||||
}
|
||||
|
||||
Version GetVersion() CXX11_OVERRIDE
|
||||
{
|
||||
return Version("Provides the pcre regular expression engine which uses the PCRE2 library.");
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(ModuleRegexPCRE2)
|
@ -26,8 +26,8 @@
|
||||
#include "modules/regex.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include "pcreposix.h"
|
||||
# pragma comment(lib, "pcreposix.lib")
|
||||
# include "pcre2posix.h"
|
||||
# pragma comment(lib, "pcre2-posix.lib")
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <regex.h>
|
||||
|
@ -12,6 +12,7 @@ libpq/14.5
|
||||
## mbedtls/3.2.1
|
||||
## openssl/1.1.1s # unable to upgrade to v3 yet because of dependency issues
|
||||
pcre/8.45
|
||||
pcre2/10.40
|
||||
re2/20220601
|
||||
sqlite3/3.39.4
|
||||
|
||||
@ -22,6 +23,7 @@ libmysqlclient:shared=True
|
||||
libpq:shared=True
|
||||
openssl:shared=True
|
||||
pcre:shared=True
|
||||
pcre2:shared=True
|
||||
re2:shared=True
|
||||
sqlite3:shared=True
|
||||
|
||||
|
@ -26,7 +26,8 @@ if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
|
||||
enable_extra("mysql" "LIBMYSQLCLIENT")
|
||||
enable_extra("pgsql" "LIBPQ")
|
||||
enable_extra("regex_pcre" "PCRE")
|
||||
enable_extra("regex_posix" "PCRE")
|
||||
enable_extra("regex_pcre2" "PCRE2")
|
||||
enable_extra("regex_posix" "PCRE2")
|
||||
enable_extra("regex_re2" "RE2")
|
||||
enable_extra("ssl_mbedtls" "MBEDTLS")
|
||||
enable_extra("ssl_openssl" "OPENSSL")
|
||||
|
Loading…
x
Reference in New Issue
Block a user