aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-31 09:33:02 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-31 09:33:02 +0100
commit7f72ec81a58eb6ed217c78f4a300781450350568 (patch)
tree8f750308db7b01f1add6a9fe9522328c7dccb6e9 /src
parent2fae860a476986fa46f1c6c33a95d8cbef832b68 (diff)
downloadrspamd-7f72ec81a58eb6ed217c78f4a300781450350568.tar.gz
rspamd-7f72ec81a58eb6ed217c78f4a300781450350568.zip
[Feature] Use XXH64 on 64 bits platforms only
Diffstat (limited to 'src')
-rw-r--r--src/libutil/logger.c7
-rw-r--r--src/libutil/str_util.c92
-rw-r--r--src/libutil/str_util.h8
-rw-r--r--src/libutil/util.c64
-rw-r--r--src/libutil/util.h8
5 files changed, 100 insertions, 79 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index c146198b3..8204efb10 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -82,6 +82,11 @@ static rspamd_logger_t *default_logger = NULL;
} \
} while (0)
+#if defined(__LP64__) || defined(_LP64)
+#define XXH_ONESHOT XXH64
+#else
+#define XXH_ONESHOT XXH32
+#endif
static void
syslog_log_function (const gchar *log_domain, const gchar *module,
@@ -101,7 +106,7 @@ static void
static inline guint64
rspamd_log_calculate_cksum (const gchar *message, size_t mlen)
{
- return XXH64 (message, mlen, rspamd_hash_seed ());
+ return XXH_ONESHOT (message, mlen, rspamd_hash_seed ());
}
/*
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index b114e3a90..601a32487 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -16,6 +16,7 @@
#include "config.h"
#include "util.h"
#include "xxhash.h"
+#include "url.h"
#include <math.h>
static const guchar lc_map[256] = {
@@ -181,6 +182,20 @@ rspamd_strcase_equal (gconstpointer v, gconstpointer v2)
return FALSE;
}
+#if defined(__LP64__) || defined(_LP64)
+#define XXH_STATE XXH64_state_t
+#define XXH_RESET XXH64_reset
+#define XXH_UPDATE XXH64_update
+#define XXH_DIGEST XXH64_digest
+#define XXH_ONESHOT XXH64
+#else
+#define XXH_STATE XXH32_state_t
+#define XXH_RESET XXH32_reset
+#define XXH_UPDATE XXH32_update
+#define XXH_DIGEST XXH32_digest
+#define XXH_ONESHOT XXH32
+#endif
+
static guint
rspamd_icase_hash (const gchar *in, gsize len)
{
@@ -193,10 +208,10 @@ rspamd_icase_hash (const gchar *in, gsize len)
} c;
guint32 pp;
} u;
- XXH64_state_t st;
+ XXH_STATE st;
fp = len - leftover;
- XXH64_reset (&st, rspamd_hash_seed ());
+ XXH_RESET (&st, rspamd_hash_seed ());
for (i = 0; i != fp; i += 4) {
u.c.c1 = s[i], u.c.c2 = s[i + 1], u.c.c3 = s[i + 2], u.c.c4 = s[i + 3];
@@ -204,7 +219,7 @@ rspamd_icase_hash (const gchar *in, gsize len)
u.c.c2 = lc_map[u.c.c2];
u.c.c3 = lc_map[u.c.c3];
u.c.c4 = lc_map[u.c.c4];
- XXH64_update (&st, &u.pp, sizeof (u));
+ XXH_UPDATE (&st, &u.pp, sizeof (u));
}
u.pp = 0;
@@ -215,11 +230,11 @@ rspamd_icase_hash (const gchar *in, gsize len)
u.c.c2 = lc_map[(guchar)s[i++]];
case 1:
u.c.c1 = lc_map[(guchar)s[i]];
- XXH64_update (&st, &u.pp, leftover);
+ XXH_UPDATE (&st, &u.pp, leftover);
break;
}
- return XXH64_digest (&st);
+ return XXH_DIGEST (&st);
}
guint
@@ -240,7 +255,7 @@ rspamd_str_hash (gconstpointer key)
len = strlen ((const gchar *)key);
- return XXH64 (key, len, rspamd_hash_seed ());
+ return XXH_ONESHOT (key, len, rspamd_hash_seed ());
}
gboolean
@@ -1597,3 +1612,68 @@ rspamd_ucl_emit_fstring_comments (const ucl_object_t *obj,
func.ud = buf;
ucl_object_emit_full (obj, emit_type, &func, comments);
}
+
+guint
+rspamd_url_hash (gconstpointer u)
+{
+ const struct rspamd_url *url = u;
+ XXH_STATE st;
+
+ XXH_RESET (&st, rspamd_hash_seed ());
+
+ if (url->urllen > 0) {
+ XXH_UPDATE (&st, url->string, url->urllen);
+ }
+
+ XXH_UPDATE (&st, &url->flags, sizeof (url->flags));
+
+ return XXH_DIGEST (&st);
+}
+
+/* Compare two emails for building emails tree */
+gboolean
+rspamd_emails_cmp (gconstpointer a, gconstpointer b)
+{
+ const struct rspamd_url *u1 = a, *u2 = b;
+ gint r;
+
+ if (u1->hostlen != u2->hostlen || u1->hostlen == 0) {
+ return FALSE;
+ }
+ else {
+ if ((r = rspamd_lc_cmp (u1->host, u2->host, u1->hostlen)) == 0) {
+ if (u1->userlen != u2->userlen || u1->userlen == 0) {
+ return FALSE;
+ }
+ else {
+ return rspamd_lc_cmp (u1->user, u2->user, u1->userlen) ==
+ 0;
+ }
+ }
+ else {
+ return r == 0;
+ }
+ }
+
+ return FALSE;
+}
+
+gboolean
+rspamd_urls_cmp (gconstpointer a, gconstpointer b)
+{
+ const struct rspamd_url *u1 = a, *u2 = b;
+ int r;
+
+ if (u1->urllen != u2->urllen) {
+ return FALSE;
+ }
+ else {
+ r = memcmp (u1->string, u2->string, u1->urllen);
+ if (r == 0 && u1->flags != u2->flags) {
+ /* Always insert phished urls to the tree */
+ return FALSE;
+ }
+ }
+
+ return r == 0;
+}
diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h
index 75cc6fb0a..04132a4d3 100644
--- a/src/libutil/str_util.h
+++ b/src/libutil/str_util.h
@@ -289,4 +289,12 @@ void rspamd_ucl_emit_fstring_comments (const ucl_object_t *obj,
rspamd_fstring_t **target,
const ucl_object_t *comments);
+guint rspamd_url_hash (gconstpointer u);
+
+/* Compare two emails for building emails hash */
+gboolean rspamd_emails_cmp (gconstpointer a, gconstpointer b);
+
+/* Compare two urls for building emails hash */
+gboolean rspamd_urls_cmp (gconstpointer a, gconstpointer b);
+
#endif /* SRC_LIBUTIL_STR_UTIL_H_ */
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 15aaac883..0ea4f4df9 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1391,70 +1391,6 @@ g_queue_free_full (GQueue *queue, GDestroyNotify free_func)
}
#endif
-guint
-rspamd_url_hash (gconstpointer u)
-{
- const struct rspamd_url *url = u;
- XXH64_state_t st;
-
- XXH64_reset (&st, rspamd_hash_seed ());
-
- if (url->urllen > 0) {
- XXH64_update (&st, url->string, url->urllen);
- }
-
- XXH64_update (&st, &url->flags, sizeof (url->flags));
-
- return XXH64_digest (&st);
-}
-
-/* Compare two emails for building emails tree */
-gboolean
-rspamd_emails_cmp (gconstpointer a, gconstpointer b)
-{
- const struct rspamd_url *u1 = a, *u2 = b;
- gint r;
-
- if (u1->hostlen != u2->hostlen || u1->hostlen == 0) {
- return FALSE;
- }
- else {
- if ((r = g_ascii_strncasecmp (u1->host, u2->host, u1->hostlen)) == 0) {
- if (u1->userlen != u2->userlen || u1->userlen == 0) {
- return FALSE;
- }
- else {
- return g_ascii_strncasecmp (u1->user, u2->user, u1->userlen) == 0;
- }
- }
- else {
- return r == 0;
- }
- }
-
- return FALSE;
-}
-
-gboolean
-rspamd_urls_cmp (gconstpointer a, gconstpointer b)
-{
- const struct rspamd_url *u1 = a, *u2 = b;
- int r;
-
- if (u1->urllen != u2->urllen) {
- return FALSE;
- }
- else {
- r = memcmp (u1->string, u2->string, u1->urllen);
- if (r == 0 && u1->flags != u2->flags) {
- /* Always insert phished urls to the tree */
- return FALSE;
- }
- }
-
- return r == 0;
-}
-
gint
rspamd_fallocate (gint fd, off_t offset, off_t len)
{
diff --git a/src/libutil/util.h b/src/libutil/util.h
index 43b0eb01b..ec8150fae 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -204,14 +204,6 @@ void g_queue_free_full (GQueue *queue, GDestroyNotify free_func);
#define ts_to_usec(ts) ((ts)->tv_sec * 1000000LLU + \
(ts)->tv_nsec / 1000LLU)
-guint rspamd_url_hash (gconstpointer u);
-
-/* Compare two emails for building emails hash */
-gboolean rspamd_emails_cmp (gconstpointer a, gconstpointer b);
-
-/* Compare two urls for building emails hash */
-gboolean rspamd_urls_cmp (gconstpointer a, gconstpointer b);
-
/**
* Try to allocate a file on filesystem (using fallocate or posix_fallocate)
* @param fd descriptor