diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-16 15:03:21 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-12-16 15:03:21 +0000 |
commit | d414e0aad91f1999b19b7ea00b2aaf24f8ecc4c6 (patch) | |
tree | 59e1145ef0d8fb555f6d9164be2c7809b2d52b4f | |
parent | 4f2046a328ab700162adc63bd98c94a0c277d374 (diff) | |
download | rspamd-d414e0aad91f1999b19b7ea00b2aaf24f8ecc4c6.tar.gz rspamd-d414e0aad91f1999b19b7ea00b2aaf24f8ecc4c6.zip |
Store fuzzy backend id based on path to file
-rw-r--r-- | src/libserver/fuzzy_backend.c | 18 | ||||
-rw-r--r-- | src/libserver/fuzzy_backend.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index 4a59e367c..d3a3d947b 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -32,6 +32,7 @@ struct rspamd_fuzzy_backend { sqlite3 *db; char *path; + gchar id[MEMPOOL_UID_LEN]; gsize count; gsize expired; rspamd_mempool_t *pool; @@ -388,6 +389,10 @@ static struct rspamd_fuzzy_backend * rspamd_fuzzy_backend_open_db (const gchar *path, GError **err) { struct rspamd_fuzzy_backend *bk; + rspamd_cryptobox_hash_state_t st; + guchar hash_out[rspamd_cryptobox_HASHBYTES]; + + g_assert (path != NULL); bk = g_slice_alloc (sizeof (*bk)); bk->path = g_strdup (path); @@ -408,6 +413,13 @@ rspamd_fuzzy_backend_open_db (const gchar *path, GError **err) return NULL; } + /* Set id for the backend */ + rspamd_cryptobox_hash_init (&st, NULL, 0); + rspamd_cryptobox_hash_update (&st, path, strlen (path)); + rspamd_cryptobox_hash_final (&st, hash_out); + rspamd_snprintf (bk->id, sizeof (bk->id), "%xs", hash_out); + memcpy (bk->pool->tag.uid, bk->id, sizeof (bk->pool->tag.uid)); + return bk; } @@ -938,3 +950,9 @@ rspamd_fuzzy_backend_expired (struct rspamd_fuzzy_backend *backend) { return backend != NULL ? backend->expired : 0; } + +const gchar * +rspamd_fuzzy_backend_id (struct rspamd_fuzzy_backend *backend) +{ + return backend != NULL ? backend->id : 0; +} diff --git a/src/libserver/fuzzy_backend.h b/src/libserver/fuzzy_backend.h index 4439d7afa..2e177e7af 100644 --- a/src/libserver/fuzzy_backend.h +++ b/src/libserver/fuzzy_backend.h @@ -98,4 +98,6 @@ void rspamd_fuzzy_backend_close (struct rspamd_fuzzy_backend *backend); gsize rspamd_fuzzy_backend_count (struct rspamd_fuzzy_backend *backend); gsize rspamd_fuzzy_backend_expired (struct rspamd_fuzzy_backend *backend); +const gchar * rspamd_fuzzy_backend_id (struct rspamd_fuzzy_backend *backend); + #endif /* FUZZY_BACKEND_H_ */ |