diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-07 03:20:42 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-07 03:20:42 +0300 |
commit | d651a97fe2551d53544d48487e3bcbbfad750eff (patch) | |
tree | 0307000a17c537a3fd460d0c71f81d19552896d5 /src/kvstorage_server.c | |
parent | 9ec83e20dcb4dd417f65ccf573a6c5de1bc20978 (diff) | |
download | rspamd-d651a97fe2551d53544d48487e3bcbbfad750eff.tar.gz rspamd-d651a97fe2551d53544d48487e3bcbbfad750eff.zip |
* Implement sync command for manual synchronization with backend.
Diffstat (limited to 'src/kvstorage_server.c')
-rw-r--r-- | src/kvstorage_server.c | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/kvstorage_server.c b/src/kvstorage_server.c index c6190454c..56f25ed97 100644 --- a/src/kvstorage_server.c +++ b/src/kvstorage_server.c @@ -199,16 +199,22 @@ parse_kvstorage_command (struct kvstorage_session *session, f_str_t *in) } } else if (p - c == 4) { - if (memcmp (c, "quit", 4) == 0) { + if (g_ascii_strncasecmp (c, "quit", 4) == 0) { session->command = KVSTORAGE_CMD_QUIT; state = 100; continue; } + if (g_ascii_strncasecmp (c, "sync", 4) == 0) { + session->command = KVSTORAGE_CMD_SYNC; + state = 100; + continue; + } } else if (p - c == 6) { - if (memcmp (c, "delete", 6) == 0) { + if (g_ascii_strncasecmp (c, "delete", 6) == 0) { session->command = KVSTORAGE_CMD_DELETE; } + else { return FALSE; } @@ -445,6 +451,41 @@ kvstorage_read_socket (f_str_t * in, void *arg) } } } + else if (session->command == KVSTORAGE_CMD_SYNC) { + if (session->cf->storage->backend == NULL || session->cf->storage->backend->sync_func == NULL) { + if (!is_redis) { + return rspamd_dispatcher_write (session->dispather, ERROR_COMMON, + sizeof (ERROR_COMMON) - 1, FALSE, TRUE); + } + else { + return rspamd_dispatcher_write (session->dispather, "-ERR unsupported" CRLF, + sizeof ("-ERR unsupported" CRLF) - 1, FALSE, TRUE); + } + } + else { + if (session->cf->storage->backend->sync_func (session->cf->storage->backend)) { + if (!is_redis) { + return rspamd_dispatcher_write (session->dispather, "SYNCED" CRLF, + sizeof ("SYNCED" CRLF) - 1, FALSE, TRUE); + } + else { + return rspamd_dispatcher_write (session->dispather, "+OK" CRLF, + sizeof ("+OK" CRLF) - 1, FALSE, TRUE); + } + } + else { + if (!is_redis) { + return rspamd_dispatcher_write (session->dispather, "NOT_SYNCED" CRLF, + sizeof ("NOT_SYNCED" CRLF) - 1, FALSE, TRUE); + } + else { + return rspamd_dispatcher_write (session->dispather, "-ERR not synced" CRLF, + sizeof ("-ERR not synced" CRLF) - 1, FALSE, TRUE); + } + } + } + g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); + } else if (session->command == KVSTORAGE_CMD_QUIT) { /* Quit session */ free_kvstorage_session (session); |