1 //
2 // Created by Vsevolod Stakhov on 2019-01-14.
3 //
4
5 #ifndef RSPAMD_SCAN_RESULT_PRIVATE_H
6 #define RSPAMD_SCAN_RESULT_PRIVATE_H
7
8 #include "scan_result.h"
9 #include "contrib/libucl/khash.h"
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #define RSPAMD_OPTS_SEED 0x9f1f608628a4fefbULL
16 #define rspamd_symopt_hash(opt) (rspamd_cryptobox_fast_hash ( \
17 ((struct rspamd_symbol_option *)opt)->option, \
18 ((struct rspamd_symbol_option *)opt)->optlen, RSPAMD_OPTS_SEED))
19 static inline bool
rspamd_symopt_equal(const struct rspamd_symbol_option * o1,const struct rspamd_symbol_option * o2)20 rspamd_symopt_equal (const struct rspamd_symbol_option *o1,
21 const struct rspamd_symbol_option *o2)
22 {
23 if (o1->optlen == o2->optlen) {
24 return (memcmp (o1->option, o2->option, o1->optlen) == 0);
25 }
26
27 return false;
28 }
29
30 KHASH_INIT (rspamd_options_hash, struct rspamd_symbol_option *, char,
31 0, rspamd_symopt_hash, rspamd_symopt_equal);
32 /**
33 * Result of metric processing
34 */
35 KHASH_MAP_INIT_STR (rspamd_symbols_hash, struct rspamd_symbol_result *);
36 #if UINTPTR_MAX <= UINT_MAX
37 /* 32 bit */
38 #define rspamd_ptr_hash_func(key) (khint32_t)(((uintptr_t)(key))>>1)
39 #else
40 /* likely 64 bit */
41 #define rspamd_ptr_hash_func(key) (khint32_t)(((uintptr_t)(key))>>3)
42 #endif
43 #define rspamd_ptr_equal_func(a, b) ((a) == (b))
44 KHASH_INIT (rspamd_symbols_group_hash,
45 void *,
46 double,
47 1,
48 rspamd_ptr_hash_func,
49 rspamd_ptr_equal_func);
50
51 #ifdef __cplusplus
52 }
53 #endif
54
55 #endif //RSPAMD_SCAN_RESULT_PRIVATE_H
56