s->nshots ++;
if (opt) {
- rspamd_task_add_result_option (task, s, opt);
+ rspamd_task_add_result_option (task, s, opt, strlen (opt));
}
/* Adjust diff */
s->score = 0;
}
- rspamd_task_add_result_option (task, s, opt);
+ if (opt) {
+ rspamd_task_add_result_option (task, s, opt, strlen (opt));
+ }
}
msg_debug_metric ("final insertion for symbol %s, score %.2f, factor: %f",
gboolean
rspamd_task_add_result_option (struct rspamd_task *task,
- struct rspamd_symbol_result *s, const gchar *val)
+ struct rspamd_symbol_result *s,
+ const gchar *val,
+ gsize vlen)
{
- struct rspamd_symbol_option *opt;
+ struct rspamd_symbol_option *opt, srch;
gboolean ret = FALSE;
gchar *opt_cpy = NULL;
- gsize vlen;
khiter_t k;
gint r;
s->options = kh_init (rspamd_options_hash);
}
- vlen = strlen (val);
-
if (vlen + s->opts_len > task->cfg->max_opts_len) {
/* Add truncated option */
msg_info_task ("cannot add more options to symbol %s when adding option %s",
if (!(s->sym && (s->sym->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) &&
kh_size (s->options) < task->cfg->default_max_shots) {
/* Append new options */
- k = kh_get (rspamd_options_hash, s->options, val);
+ srch.option = (gchar *)val;
+ srch.optlen = vlen;
+ k = kh_get (rspamd_options_hash, s->options, &srch);
if (k == kh_end (s->options)) {
opt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*opt));
opt_cpy = rspamd_mempool_strdup (task->task_pool, val);
}
- k = kh_put (rspamd_options_hash, s->options, opt_cpy, &r);
+ opt->optlen = vlen;
+ opt->option = opt_cpy;
- kh_value (s->options, k) = opt;
+ k = kh_put (rspamd_options_hash, s->options, opt, &r);
opt->option = opt_cpy;
DL_APPEND (s->opts_head, opt);
extern "C" {
#endif
-KHASH_MAP_INIT_STR (rspamd_options_hash, struct rspamd_symbol_option *);
+#define RSPAMD_OPTS_SEED 0x9f1f608628a4fefbULL
+#define rspamd_symopt_hash(opt) (rspamd_cryptobox_fast_hash ( \
+ ((struct rspamd_symbol_option *)opt)->option, \
+ ((struct rspamd_symbol_option *)opt)->optlen, RSPAMD_OPTS_SEED))
+static inline bool
+rspamd_symopt_equal (const struct rspamd_symbol_option *o1,
+ const struct rspamd_symbol_option *o2)
+{
+ if (o1->optlen == o2->optlen) {
+ return (memcmp (o1->option, o2->option, o1->optlen) == 0);
+ }
+
+ return false;
+}
+
+KHASH_INIT (rspamd_options_hash, struct rspamd_symbol_option *, char,
+ 0, rspamd_symopt_hash, rspamd_symopt_equal);
/**
* Result of metric processing
*/