#ifdef WITH_HYPERSCAN
#include "hs.h"
+#include "hyperscan_tools.h"
#endif
#include "unix-std.h"
gchar hash[rspamd_cryptobox_HASHBYTES + 1];
#ifdef WITH_HYPERSCAN
- hs_database_t *hs_db;
+ rspamd_hyperscan_t *hs_db;
hs_scratch_t *hs_scratch;
gint *hs_ids;
guint nhs;
#ifdef WITH_HYPERSCAN
if (re_class->hs_db) {
- hs_free_database (re_class->hs_db);
+ rspamd_hyperscan_free(re_class->hs_db);
}
if (re_class->hs_scratch) {
hs_free_scratch (re_class->hs_scratch);
cbdata.count = 1;
cbdata.task = task;
- if ((hs_scan (re_class->hs_db, in[i], lens[i], 0,
+ if ((hs_scan (rspamd_hyperscan_get_database(re_class->hs_db),
+ in[i], lens[i], 0,
re_class->hs_scratch,
rspamd_re_cache_hyperscan_cb, &cbdata)) != HS_SUCCESS) {
ret = 0;
gint fd, i, n, *hs_ids = NULL, *hs_flags = NULL, total = 0, ret;
GHashTableIter it;
gpointer k, v;
- guint8 *map, *p, *end;
+ guint8 *map, *p;
struct rspamd_re_class *re_class;
struct rspamd_re_cache_elt *elt;
struct stat st;
}
close (fd);
- end = map + st.st_size;
p = map + RSPAMD_HS_MAGIC_LEN + sizeof (cache->plt);
n = *(gint *)p;
}
if (re_class->hs_db != NULL) {
- hs_free_database (re_class->hs_db);
+ rspamd_hyperscan_free (re_class->hs_db);
}
if (re_class->hs_ids) {
re_class->hs_ids = NULL;
re_class->hs_scratch = NULL;
re_class->hs_db = NULL;
+ munmap (map, st.st_size);
- if ((ret = hs_deserialize_database (p, end - p, &re_class->hs_db))
- != HS_SUCCESS) {
+ re_class->hs_db = rspamd_hyperscan_maybe_load(path, p - map);
+ if (re_class->hs_db == NULL) {
if (!try_load) {
- msg_err_re_cache ("bad hs database in %s: %d", path, ret);
+ msg_err_re_cache ("bad hs database in %s", path);
}
else {
- msg_debug_re_cache ("bad hs database in %s: %d", path, ret);
+ msg_debug_re_cache ("bad hs database in %s", path);
}
- munmap (map, st.st_size);
g_free (hs_ids);
g_free (hs_flags);
continue;
}
- munmap (map, st.st_size);
-
- g_assert (hs_alloc_scratch (re_class->hs_db,
- &re_class->hs_scratch) == HS_SUCCESS);
+ if ((ret = hs_alloc_scratch (rspamd_hyperscan_get_database(re_class->hs_db),
+ &re_class->hs_scratch)) != HS_SUCCESS) {
+ msg_err_re_cache ("fatal error: cannot allocate scratch for %s: %d", path, ret);
+ g_abort();
+ }
/*
* Now find hyperscan elts that are successfully compiled and