diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-01-19 17:01:08 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-01-19 17:01:08 +0300 |
commit | 87c9659fdd08bbbc0eb796afccf7237a03181498 (patch) | |
tree | 9d18d2064ac00b566c48eda1c1b58a31f8c7dd72 /src | |
parent | fe5ad5874aad220fb12a259e607f89ce5fae7465 (diff) | |
download | rspamd-87c9659fdd08bbbc0eb796afccf7237a03181498.tar.gz rspamd-87c9659fdd08bbbc0eb796afccf7237a03181498.zip |
* Rewrite perl client for rspamd, now it allows access to both normal and control interfaces
* Fix small errors in tokenizer and controller interface
Diffstat (limited to 'src')
-rw-r--r-- | src/controller.c | 16 | ||||
-rw-r--r-- | src/fstring.c | 16 | ||||
-rw-r--r-- | src/fstring.h | 6 | ||||
-rw-r--r-- | src/statfile.c | 6 | ||||
-rw-r--r-- | src/tokenizers/osb.c | 1 | ||||
-rw-r--r-- | src/tokenizers/tokenizers.c | 6 |
6 files changed, 42 insertions, 9 deletions
diff --git a/src/controller.c b/src/controller.c index fb14cf8bb..56eeb042a 100644 --- a/src/controller.c +++ b/src/controller.c @@ -26,6 +26,7 @@ #include "classifiers/classifiers.h" #define CRLF "\r\n" +#define END "END" CRLF enum command_type { COMMAND_PASSWORD, @@ -149,9 +150,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control } break; case COMMAND_QUIT: - session->state = STATE_QUIT; - r = snprintf (out_buf, sizeof (out_buf), "bye" CRLF); - bufferevent_write (session->bev, out_buf, r); + session->state = STATE_QUIT; break; case COMMAND_RELOAD: if (check_auth (cmd, session)) { @@ -170,7 +169,6 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control session->worker->srv->stat->connections_count); r += snprintf (out_buf + r, sizeof (out_buf) - r, "Control connections count: %u" CRLF, session->worker->srv->stat->control_connections_count); - r += snprintf (out_buf + r, sizeof (out_buf) - r, "-- end of stats report" CRLF); bufferevent_write (session->bev, out_buf, r); } break; @@ -187,8 +185,8 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control /* If uptime more than 2 hours, print as a number of days. */ if (uptime >= 2 * 3600) { days = uptime / 86400; - hours = (uptime % 3600) / 60; - minutes = (uptime % 60) / 60; + hours = uptime / 3600 - days * 86400; + minutes = uptime / 60 - hours * 3600 - days * 86400; r = snprintf (out_buf, sizeof (out_buf), "%d day%s %d hour%s %d minute%s" CRLF, days, days > 1 ? "s" : " ", hours, hours > 1 ? "s" : " ", @@ -201,7 +199,7 @@ process_command (struct controller_command *cmd, char **cmd_args, struct control /* Else print the minutes and seconds. */ else { hours = uptime / 3600; - minutes = (uptime % 60) / 60; + minutes = uptime / 60 - hours * 3600; r = snprintf (out_buf, sizeof (out_buf), "%d hour%s %d minite%s %d second%s" CRLF, hours, hours > 1 ? "s" : " ", minutes, minutes > 1 ? "s" : " ", @@ -371,10 +369,14 @@ read_socket (struct bufferevent *bev, void *arg) session->state = STATE_REPLY; } if (session->state != STATE_LEARN) { + bufferevent_write (bev, END, sizeof (END) - 1); bufferevent_enable (bev, EV_WRITE); } g_strfreev (params); } + else { + bufferevent_enable (bev, EV_WRITE); + } if (s != NULL) { free (s); } diff --git a/src/fstring.c b/src/fstring.c index 2935fe8e6..b2008c047 100644 --- a/src/fstring.c +++ b/src/fstring.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include "fstring.h" @@ -155,6 +156,21 @@ fstrcat (f_str_t *dest, f_str_t *src) } /* + * Make copy of string to 0-terminated string + */ +char* +fstrcstr (f_str_t *str, memory_pool_t *pool) +{ + char *res; + res = memory_pool_alloc (pool, str->len + 1); + + memcpy (res, str->begin, str->len); + res[str->len] = 0; + + return res; +} + +/* * Push one character to fstr */ int diff --git a/src/fstring.h b/src/fstring.h index 6840d9088..896cd8dcf 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -93,4 +93,10 @@ f_str_t* fstrgrow (memory_pool_t *pool, f_str_t *orig, size_t newlen); */ uint32_t fstrhash (f_str_t *str); + +/* + * Make copy of string to 0-terminated string + */ +char* fstrcstr (f_str_t *str, memory_pool_t *pool); + #endif diff --git a/src/statfile.c b/src/statfile.c index c0a2a2487..830bc5960 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -337,6 +337,12 @@ statfile_pool_set_block (statfile_pool_t *pool, char *filename, uint32_t h1, uin msg_debug ("statfile_pool_set_block: chain %u is full, starting expire", blocknum); break; } + /* First try to find block in chain */ + if (block->hash1 == h1 && block->hash2 == h2) { + block->last_access = now - (time_t)header->create_time; + block->value = value; + return; + } /* Check whether we have a free block in chain */ if (block->hash1 == 0 && block->hash2 == 0) { /* Write new block here */ diff --git a/src/tokenizers/osb.c b/src/tokenizers/osb.c index afd2febd8..451644675 100644 --- a/src/tokenizers/osb.c +++ b/src/tokenizers/osb.c @@ -43,6 +43,7 @@ osb_tokenize_text (struct tokenizer *tokenizer, memory_pool_t *pool, f_str_t *in hashpipe[i] = hashpipe[i - 1]; } hashpipe[0] = fstrhash (&token); + msg_debug ("osb_tokenize_text: text token %s, hash: %d", fstrcstr (&token, pool), hashpipe[0]); for (i = 1; i < FEATURE_WINDOW_SIZE; i ++) { h1 = hashpipe[0]* primes[0] + hashpipe[i] * primes[i<<1]; diff --git a/src/tokenizers/tokenizers.c b/src/tokenizers/tokenizers.c index 280ebd477..f0481e00d 100644 --- a/src/tokenizers/tokenizers.c +++ b/src/tokenizers/tokenizers.c @@ -60,11 +60,13 @@ get_next_word (f_str_t *buf, f_str_t *token) pos = token->begin; /* Skip non graph symbols */ - while (remain-- && !g_ascii_isgraph (*pos ++)) { + while (remain-- && !g_ascii_isgraph (*pos)) { token->begin ++; + pos ++; } - while (remain-- && g_ascii_isgraph (*pos ++)) { + while (remain-- && g_ascii_isgraph (*pos)) { token->len ++; + pos ++; } if (token->len == 0) { |