From bfda3c0113c0c2eb4284ad428a84c7db2fa4b9e3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 6 Nov 2009 20:47:07 +0300 Subject: [PATCH] * Add logging urls as it was required by rambler search --- src/cfg_file.h | 1 + src/cfg_file.l | 1 + src/cfg_file.y | 10 +++++++++- src/protocol.c | 17 ++++++++++++++++- src/util.c | 2 -- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/cfg_file.h b/src/cfg_file.h index b165e82f2..f2cd97e23 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -205,6 +205,7 @@ struct config_file { char *log_file; /**< path to logfile in case of file logging */ int log_fd; /**< log descriptor in case of file logging */ FILE *logf; + gboolean log_urls; /**< whether we should log URLs */ size_t max_statfile_size; /**< maximum size for statfile */ diff --git a/src/cfg_file.l b/src/cfg_file.l index 822cab3fa..bc46bbc1f 100644 --- a/src/cfg_file.l +++ b/src/cfg_file.l @@ -88,6 +88,7 @@ log_type return LOG_TYPE; console return LOG_TYPE_CONSOLE; syslog return LOG_TYPE_SYSLOG; file return LOG_TYPE_FILE; +log_urls return LOG_URLS; log_level return LOG_LEVEL; DEBUG return LOG_LEVEL_DEBUG; diff --git a/src/cfg_file.y b/src/cfg_file.y index 8ac9cb6a5..dbee3a0bd 100644 --- a/src/cfg_file.y +++ b/src/cfg_file.y @@ -54,7 +54,7 @@ struct rspamd_view *cur_view = NULL; %token FILTERS FACTORS METRIC NAME CACHE_FILE %token REQUIRED_SCORE REJECT_SCORE FUNCTION FRACT COMPOSITES CONTROL PASSWORD %token LOGGING LOG_TYPE LOG_TYPE_CONSOLE LOG_TYPE_SYSLOG LOG_TYPE_FILE -%token LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME +%token LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME LOG_URLS %token STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER %token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE PROFILE_FILE COUNT %token VIEW IP FROM SYMBOLS CLIENT_IP @@ -563,6 +563,7 @@ loggingcmd: | logginglevel | loggingfacility | loggingfile + | loggingurls ; loggingtype: @@ -650,6 +651,13 @@ loggingfile: } ; +loggingurls: + LOG_URLS EQSIGN FLAG { + if ($3 != 0) { + cfg->log_urls = TRUE; + } + } + ; classifier: CLASSIFIER OBRACE classifierbody EBRACE { diff --git a/src/protocol.c b/src/protocol.c index 3758de8a2..b89d5767a 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -87,6 +87,9 @@ static GList *custom_commands = NULL; +/* For default metric, dirty hack, but much faster than hash lookup */ +static double default_score, default_required_score; + static char * separate_command (f_str_t * in, char c) { @@ -414,6 +417,10 @@ show_url_header (struct worker_task *task) cur = task->urls; while (cur) { url = cur->data; + if (task->cfg->log_urls) { + /* Write this url to log as well */ + msg_info ("process_message: url found: <%s>, score: [%.2f / %.2f]", struri (url), default_score, default_required_score); + } host.begin = url->host; host.len = url->hostlen; /* Skip long hosts to avoid protocol coollisions */ @@ -530,7 +537,9 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data if (metric_name == NULL || metric_value == NULL) { - m = g_hash_table_lookup (task->cfg->metrics, "default"); + m = g_hash_table_lookup (task->cfg->metrics, DEFAULT_METRIC); + default_required_score = m->required_score; + default_score = 0; if (!check_metric_settings (task, m, &ms, &rs)) { ms = m->required_score; rs = m->reject_score; @@ -559,6 +568,12 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data } } else { + /* XXX: dirty hack */ + if (strcmp (metric_res->metric->name, DEFAULT_METRIC) == 0) { + default_required_score = metric_res->metric->required_score; + default_score = metric_res->score; + } + if (!check_metric_settings (task, metric_res->metric, &ms, &rs)) { ms = metric_res->metric->required_score; rs = metric_res->metric->reject_score; diff --git a/src/util.c b/src/util.c index 425aed439..732d67386 100644 --- a/src/util.c +++ b/src/util.c @@ -749,8 +749,6 @@ close_log (struct config_file *cfg) msg_err ("close_log: error syncing log file: %s", strerror (errno)); } fclose (cfg->logf); - /* XXX: I think this is not needed */ - close (cfg->log_fd); } break; } -- 2.39.5