diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-17 21:05:54 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-17 21:05:54 +0300 |
commit | c2a5be027167c3558e1f22955835eead50cecaba (patch) | |
tree | ac804a1f2835f4f8625636a32ddcbe7ce15431a4 /src/kvstorage_server.c | |
parent | 7a8ddd6a019b7289722c546f9c90961c70f2c91c (diff) | |
download | rspamd-c2a5be027167c3558e1f22955835eead50cecaba.tar.gz rspamd-c2a5be027167c3558e1f22955835eead50cecaba.zip |
* Implement binary safe keys.
* Use more fast hashing.
Diffstat (limited to 'src/kvstorage_server.c')
-rw-r--r-- | src/kvstorage_server.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/kvstorage_server.c b/src/kvstorage_server.c index dd0c18b57..3f072654d 100644 --- a/src/kvstorage_server.c +++ b/src/kvstorage_server.c @@ -307,6 +307,7 @@ parse_kvstorage_line (struct kvstorage_session *session, f_str_t *in) else { session->key = memory_pool_alloc (session->pool, p - c + 1); rspamd_strlcpy (session->key, c, p - c + 1); + session->keylen = p - c; /* Now we must select next state based on command */ if (session->command == KVSTORAGE_CMD_SET || session->command == KVSTORAGE_CMD_INCR || @@ -473,7 +474,7 @@ kvstorage_process_command (struct kvstorage_session *session, gboolean is_redis) } else if (session->command == KVSTORAGE_CMD_GET) { g_static_rw_lock_reader_lock (&session->cf->storage->rwlock); - elt = rspamd_kv_storage_lookup (session->cf->storage, session->key, session->now); + elt = rspamd_kv_storage_lookup (session->cf->storage, session->key, session->keylen, session->now); if (elt == NULL) { g_static_rw_lock_reader_unlock (&session->cf->storage->rwlock); if (!is_redis) { @@ -537,7 +538,7 @@ kvstorage_process_command (struct kvstorage_session *session, gboolean is_redis) } else if (session->command == KVSTORAGE_CMD_DELETE) { g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); - elt = rspamd_kv_storage_delete (session->cf->storage, session->key); + elt = rspamd_kv_storage_delete (session->cf->storage, session->key, session->keylen); if (elt != NULL) { if ((elt->flags & KV_ELT_DIRTY) == 0) { /* Free memory if backend has deleted this element */ @@ -568,7 +569,7 @@ kvstorage_process_command (struct kvstorage_session *session, gboolean is_redis) else if (session->command == KVSTORAGE_CMD_INCR || session->command == KVSTORAGE_CMD_DECR) { g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); longval = session->arg_data.value; - if (!rspamd_kv_storage_increment (session->cf->storage, session->key, &longval)) { + if (!rspamd_kv_storage_increment (session->cf->storage, session->key, session->keylen, &longval)) { g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock); if (!is_redis) { return rspamd_dispatcher_write (session->dispather, ERROR_NOT_FOUND, @@ -815,6 +816,7 @@ kvstorage_read_socket (f_str_t * in, void *arg) if (session->command != KVSTORAGE_CMD_SELECT) { /* This argument is a key for normal command */ session->key = memory_pool_fstrdup (session->pool, in); + session->keylen = in->len; if (session->argnum == session->argc - 1) { session->state = KVSTORAGE_STATE_READ_CMD; rspamd_set_dispatcher_policy (session->dispather, BUFFER_LINE, -1); @@ -841,7 +843,8 @@ kvstorage_read_socket (f_str_t * in, void *arg) session->state = KVSTORAGE_STATE_READ_CMD; rspamd_set_dispatcher_policy (session->dispather, BUFFER_LINE, -1); g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); - if (rspamd_kv_storage_insert (session->cf->storage, session->key, in->begin, in->len, + if (rspamd_kv_storage_insert (session->cf->storage, session->key, session->keylen, + in->begin, in->len, session->flags, session->expire)) { g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock); return rspamd_dispatcher_write (session->dispather, "+OK" CRLF, @@ -868,7 +871,8 @@ kvstorage_read_socket (f_str_t * in, void *arg) session->state = KVSTORAGE_STATE_READ_CMD; rspamd_set_dispatcher_policy (session->dispather, BUFFER_LINE, -1); g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); - if (rspamd_kv_storage_insert (session->cf->storage, session->key, in->begin, in->len, + if (rspamd_kv_storage_insert (session->cf->storage, session->key, session->keylen, + in->begin, in->len, session->flags, session->expire)) { g_static_rw_lock_writer_unlock (&session->cf->storage->rwlock); if (!is_redis) { |