diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-08 02:47:39 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-11-08 02:47:39 +0300 |
commit | 6bf5ab75b75437a1b687ac562438cce116845c61 (patch) | |
tree | e2bd5da2d7f982abbfd952a0f357b6655e22bd11 | |
parent | 229fd540109f92cb8662dd085fcfe46aad3130cf (diff) | |
download | rspamd-6bf5ab75b75437a1b687ac562438cce116845c61.tar.gz rspamd-6bf5ab75b75437a1b687ac562438cce116845c61.zip |
Imlement 'select' and 'save' commands.
-rw-r--r-- | src/kvstorage_server.c | 42 | ||||
-rw-r--r-- | src/kvstorage_server.h | 1 |
2 files changed, 40 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); diff --git a/src/kvstorage_server.h b/src/kvstorage_server.h index 3b475ebd0..2d4a3fa89 100644 --- a/src/kvstorage_server.h +++ b/src/kvstorage_server.h @@ -66,6 +66,7 @@ struct kvstorage_session { KVSTORAGE_CMD_GET, KVSTORAGE_CMD_DELETE, KVSTORAGE_CMD_SYNC, + KVSTORAGE_CMD_SELECT, KVSTORAGE_CMD_QUIT } command; guint id; |