#define MAX_SCRATCH 4
+enum rspamd_hs_check_state {
+ RSPAMD_HS_UNCHECKED = 0,
+ RSPAMD_HS_SUPPORTED,
+ RSPAMD_HS_UNSUPPORTED
+};
+
static const char *hs_cache_dir = NULL;
-#ifdef WITH_HYPERSCAN
-static gboolean hs_suitable_cpu = FALSE;
-#endif
+static enum rspamd_hs_check_state hs_suitable_cpu = RSPAMD_HS_UNCHECKED;
+
struct rspamd_multipattern {
#ifdef WITH_HYPERSCAN
return g_quark_from_static_string ("multipattern");
}
+static inline gboolean
+rspamd_hs_check (void)
+{
+#ifdef WITH_HYPERSCAN
+ if (G_UNLIKELY (hs_suitable_cpu == RSPAMD_HS_UNCHECKED)) {
+ if (hs_valid_platform () == HS_SUCCESS) {
+ hs_suitable_cpu = RSPAMD_HS_SUPPORTED;
+ }
+ else {
+ hs_suitable_cpu = RSPAMD_HS_UNSUPPORTED;
+ }
+ }
+#endif
+
+ return hs_suitable_cpu == RSPAMD_HS_SUPPORTED;
+}
+
void
-rspamd_multipattern_library_init (const gchar *cache_dir,
- struct rspamd_cryptobox_library_ctx *crypto_ctx)
+rspamd_multipattern_library_init (const gchar *cache_dir)
{
hs_cache_dir = cache_dir;
#ifdef WITH_HYPERSCAN
- if (crypto_ctx->cpu_config & CPUID_SSSE3) {
- hs_suitable_cpu = TRUE;
- }
+ rspamd_hs_check ();
#endif
}
{
gchar *ret = NULL;
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
if (flags & RSPAMD_MULTIPATTERN_TLD) {
ret = rspamd_multipattern_escape_tld_hyperscan (pattern, len, dst_len);
}
mp->flags = flags;
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
mp->hs_pats = g_array_new (FALSE, TRUE, sizeof (gchar *));
mp->hs_flags = g_array_new (FALSE, TRUE, sizeof (gint));
mp->hs_ids = g_array_new (FALSE, TRUE, sizeof (gint));
mp->flags = flags;
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
mp->hs_pats = g_array_sized_new (FALSE, TRUE, sizeof (gchar *), npatterns);
mp->hs_flags = g_array_sized_new (FALSE, TRUE, sizeof (gint), npatterns);
mp->hs_ids = g_array_sized_new (FALSE, TRUE, sizeof (gint), npatterns);
g_assert (!mp->compiled);
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
gchar *np;
gint fl = HS_FLAG_SOM_LEFTMOST;
g_assert (!mp->compiled);
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
guint i;
hs_platform_info_t plt;
hs_compile_error_t *hs_errors;
cbd.ret = 0;
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
hs_scratch_t *scr = NULL;
guint i;
if (mp) {
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
gchar *p;
if (mp->compiled && mp->cnt > 0) {
g_assert (index < mp->cnt);
#ifdef WITH_HYPERSCAN
- if (hs_suitable_cpu) {
+ if (rspamd_hs_check ()) {
return g_array_index (mp->hs_pats, gchar *, index);
}
#endif
return mp->cnt;
}
+
+gboolean
+rspamd_multipattern_has_hyperscan (void)
+{
+ return rspamd_hs_check ();
+}
\ No newline at end of file
* Init multipart library and set the appropriate cache dir
* @param cache_dir
*/
-void rspamd_multipattern_library_init (const gchar *cache_dir,
- struct rspamd_cryptobox_library_ctx *crypto_ctx);
+void rspamd_multipattern_library_init (const gchar *cache_dir);
/**
* Creates empty multipattern structure
* @param reserved
* @return
*/
-struct rspamd_multipattern *rspamd_multipattern_create_sized (
- enum rspamd_multipattern_flags flags, guint reserved);
+struct rspamd_multipattern *rspamd_multipattern_create_sized (guint reserved,
+ enum rspamd_multipattern_flags flags);
/**
* Creates new multipattern structure
*/
void rspamd_multipattern_destroy (struct rspamd_multipattern *mp);
+/**
+ * Returns TRUE if hyperscan is supported
+ * @return
+ */
+gboolean rspamd_multipattern_has_hyperscan (void);
+
#endif /* SRC_LIBUTIL_MULTIPATTERN_H_ */