diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-08 18:28:37 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-08 18:28:37 +0300 |
commit | d8f9f8f6c64001dab5f0357b1c6af93bf6c3eea5 (patch) | |
tree | 031c01dee3984326da287096a04faafddf375bd1 /src/kvstorage_server.c | |
parent | 6219ae33bf0c5f05a1ffce6db56f9a7384142814 (diff) | |
parent | 6bf5ab75b75437a1b687ac562438cce116845c61 (diff) | |
download | rspamd-d8f9f8f6c64001dab5f0357b1c6af93bf6c3eea5.tar.gz rspamd-d8f9f8f6c64001dab5f0357b1c6af93bf6c3eea5.zip |
Forgot to merge.
Diffstat (limited to 'src/kvstorage_server.c')
-rw-r--r-- | src/kvstorage_server.c | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/kvstorage_server.c b/src/kvstorage_server.c index 620c5c73f..d91eaa1c8 100644 --- a/src/kvstorage_server.c +++ b/src/kvstorage_server.c @@ -204,7 +204,7 @@ parse_kvstorage_command (struct kvstorage_session *session, f_str_t *in) state = 100; continue; } - if (g_ascii_strncasecmp (c, "sync", 4) == 0) { + if (g_ascii_strncasecmp (c, "sync", 4) == 0 || g_ascii_strncasecmp (c, "save", 4) == 0) { session->command = KVSTORAGE_CMD_SYNC; state = 100; continue; @@ -214,7 +214,12 @@ parse_kvstorage_command (struct kvstorage_session *session, f_str_t *in) if (g_ascii_strncasecmp (c, "delete", 6) == 0) { session->command = KVSTORAGE_CMD_DELETE; } - + else if (g_ascii_strncasecmp (c, "select", 6) == 0) { + session->command = KVSTORAGE_CMD_SELECT; + state = 99; + next_state = 6; + continue; + } else { return FALSE; } @@ -311,6 +316,21 @@ parse_kvstorage_command (struct kvstorage_session *session, f_str_t *in) } } break; + case 6: + /* Read index of storage */ + if (g_ascii_isdigit (*p)) { + p ++; + } + else { + if (g_ascii_isspace (*p) || end == p) { + session->id = strtoul (c, NULL, 10); + state = 100; + } + else { + return FALSE; + } + } + break; case 99: /* Skip spaces state */ if (g_ascii_isspace (*p)) { @@ -374,8 +394,14 @@ kvstorage_read_socket (f_str_t * in, void *arg) session->cf = get_kvstorage_config (session->id); if (session->cf == NULL) { thr_info ("%ud: bad keystorage: %ud", thr->id, session->id); - return rspamd_dispatcher_write (session->dispather, ERROR_INVALID_KEYSTORAGE, + if (!is_redis) { + return rspamd_dispatcher_write (session->dispather, ERROR_INVALID_KEYSTORAGE, sizeof (ERROR_INVALID_KEYSTORAGE) - 1, FALSE, TRUE); + } + else { + return rspamd_dispatcher_write (session->dispather, "-ERR unknown keystorage" CRLF, + sizeof ("-ERR unknown keystorage" CRLF) - 1, FALSE, TRUE); + } } if (session->command == KVSTORAGE_CMD_SET) { session->state = KVSTORAGE_STATE_READ_DATA; @@ -495,6 +521,16 @@ kvstorage_read_socket (f_str_t * in, void *arg) } g_static_rw_lock_writer_lock (&session->cf->storage->rwlock); } + else if (session->command == KVSTORAGE_CMD_SELECT) { + if (!is_redis) { + return rspamd_dispatcher_write (session->dispather, "SELECTED" CRLF, + sizeof ("SELECTED" CRLF) - 1, FALSE, TRUE); + } + else { + return rspamd_dispatcher_write (session->dispather, "+OK" CRLF, + sizeof ("+OK" CRLF) - 1, FALSE, TRUE); + } + } else if (session->command == KVSTORAGE_CMD_QUIT) { /* Quit session */ free_kvstorage_session (session); |