diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-29 11:52:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-11-29 11:52:32 +0000 |
commit | b01d5d5a5f6f8d272827f0b447971f0786fc30b7 (patch) | |
tree | adb9d71d4b42bd6b36babe6610249846383690ff /src | |
parent | b39a9f52ed3f33082f13f51678d053ee80a2e1f4 (diff) | |
download | rspamd-b01d5d5a5f6f8d272827f0b447971f0786fc30b7.tar.gz rspamd-b01d5d5a5f6f8d272827f0b447971f0786fc30b7.zip |
[Minor] Various fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/cxx/rspamd-simdutf.cxx | 37 | ||||
-rw-r--r-- | src/libutil/rspamd_simdutf.h | 2 | ||||
-rw-r--r-- | src/rspamd.c | 2 |
3 files changed, 39 insertions, 2 deletions
diff --git a/src/libutil/cxx/rspamd-simdutf.cxx b/src/libutil/cxx/rspamd-simdutf.cxx index 67b585812..811403884 100644 --- a/src/libutil/cxx/rspamd-simdutf.cxx +++ b/src/libutil/cxx/rspamd-simdutf.cxx @@ -23,14 +23,36 @@ extern "C" { +const simdutf::implementation *impl{nullptr}; +const simdutf::implementation *ref_impl{nullptr}; + void rspamd_fast_utf8_library_init(unsigned flags) { - // This library requires no initialisation + impl = simdutf::get_active_implementation(); + auto all_impls = simdutf::get_available_implementations(); + + for (auto &i: all_impls) { + if (i->name() == "fallback") { + ref_impl = i; + break; + } + } } off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len) { - auto res = simdutf::validate_utf8_with_errors((const char *) data, len); + auto res = impl->validate_utf8_with_errors((const char *) data, len); + + if (res.error == simdutf::error_code::SUCCESS) { + return 0; + } + + return res.count + 1;// We need to return offset for the first invalid character +} + +off_t rspamd_fast_utf8_validate_ref(const unsigned char *data, size_t len) +{ + auto res = ref_impl->validate_utf8_with_errors((const char *) data, len); if (res.error == simdutf::error_code::SUCCESS) { return 0; @@ -38,4 +60,15 @@ off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len) return res.count + 1;// We need to return offset for the first invalid character } + +const char *rspamd_fast_utf8_library_impl_name(void) +{ + static auto impl_name = std::string{}; + + if (impl_name.empty()) { + impl_name = impl->name() + "(" + impl->description() + ")"; + } + + return impl_name.c_str(); +} }
\ No newline at end of file diff --git a/src/libutil/rspamd_simdutf.h b/src/libutil/rspamd_simdutf.h index c1fa07892..23384de4c 100644 --- a/src/libutil/rspamd_simdutf.h +++ b/src/libutil/rspamd_simdutf.h @@ -25,7 +25,9 @@ extern "C" { #endif void rspamd_fast_utf8_library_init(unsigned flags); +const char *rspamd_fast_utf8_library_impl_name(void); off_t rspamd_fast_utf8_validate(const unsigned char *data, size_t len); +off_t rspamd_fast_utf8_validate_ref(const unsigned char *data, size_t len); #ifdef __cplusplus } diff --git a/src/rspamd.c b/src/rspamd.c index 6c204e266..088bfba49 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -56,6 +56,7 @@ #ifdef WITH_HYPERSCAN #include "libserver/hyperscan_tools.h" +#include "rspamd_simdutf.h" #endif /* 2 seconds to fork new process in place of dead one */ @@ -1551,6 +1552,7 @@ int main(int argc, char **argv, char **env) rspamd_main->cfg->libs_ctx->crypto_ctx->chacha20_impl, rspamd_main->cfg->libs_ctx->crypto_ctx->base64_impl); msg_info_main("libottery prf: %s", ottery_get_impl_name()); + msg_info_main("simdutf implementation: %s", rspamd_fast_utf8_library_impl_name()); /* Daemonize */ if (!no_fork) { |