aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-07-05 17:48:20 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-07-05 17:48:20 +0400
commit52e71f9ed43b0e0f7f030eb0f0b56a887978cf8a (patch)
tree9496a3ea6f3b95006554b003e01425e6b68b2765
parentbae637bec8e9c23668cbacbb9f5a1bd829cae487 (diff)
downloadrspamd-52e71f9ed43b0e0f7f030eb0f0b56a887978cf8a.tar.gz
rspamd-52e71f9ed43b0e0f7f030eb0f0b56a887978cf8a.zip
* Fix detection of numeric urls (reported by citrin)
* Write real time of message's scan to log (not only virtual)
-rw-r--r--src/main.h3
-rw-r--r--src/plugins/surbl.c2
-rw-r--r--src/protocol.c6
-rw-r--r--src/smtp.c6
-rw-r--r--src/url.c15
-rw-r--r--src/util.c29
-rw-r--r--src/util.h2
-rw-r--r--src/worker.c3
8 files changed, 39 insertions, 27 deletions
diff --git a/src/main.h b/src/main.h
index 233fd6159..defa25c0d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -211,9 +211,8 @@ struct worker_task {
memory_pool_t *task_pool; /**< memory pool for task */
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts; /**< time of connection */
-#else
- struct timeval tv; /**< time of connection */
#endif
+ struct timeval tv; /**< time of connection */
struct rspamd_view *view; /**< matching view */
gboolean view_checked;
gboolean pass_all_filters; /**< pass task throught every rule */
diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index 8c9d2ccb0..f50bd8976 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -371,7 +371,7 @@ format_surbl_request (memory_pool_t * pool, f_str_t * hostname, struct suffix_it
/* Hack for bugged windows resolver */
ip_num &= 0xFFFFFFFF;
/* Get octets */
- r = rspamd_snprintf (result, len, "%u.%u.%u.%u",
+ r = rspamd_snprintf (result, len, "%ud.%ud.%ud.%ud",
(uint32_t) ip_num & 0x000000FF, (uint32_t) (ip_num & 0x0000FF00) >> 8, (uint32_t) (ip_num & 0x00FF0000) >> 16, (uint32_t) (ip_num & 0xFF000000) >> 24);
}
else {
diff --git a/src/protocol.c b/src/protocol.c
index 98d68bf12..76627e15e 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -697,10 +697,10 @@ show_metric_result (gpointer metric_name, gpointer metric_value, void *user_data
}
}
#ifdef HAVE_CLOCK_GETTIME
- cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %sms",
- (long int)task->msg->len, calculate_check_time (&task->ts, task->cfg->clock_res));
+ cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %s,",
+ (long int)task->msg->len, calculate_check_time (&task->tv, &task->ts, task->cfg->clock_res));
#else
- cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %sms",
+ cd->log_offset += rspamd_snprintf (cd->log_buf + cd->log_offset, cd->log_size - cd->log_offset, "]), len: %l, time: %s,",
(long int)task->msg->len, calculate_check_time (&task->tv, task->cfg->clock_res));
#endif
}
diff --git a/src/smtp.c b/src/smtp.c
index 8f3411b02..885a1f681 100644
--- a/src/smtp.c
+++ b/src/smtp.c
@@ -578,10 +578,10 @@ smtp_write_socket (void *arg)
}
g_list_free (symbols);
#ifdef HAVE_CLOCK_GETTIME
- r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %sms",
- (long int)session->task->msg->len, calculate_check_time (&session->task->ts, session->cfg->clock_res));
+ r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %s",
+ (long int)session->task->msg->len, calculate_check_time (&session->task->tv, &session->task->ts, session->cfg->clock_res));
#else
- r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %sms",
+ r += rspamd_snprintf (logbuf + r, sizeof (logbuf) - r, "]), len: %l, time: %s",
(long int)session->task->msg->len, calculate_check_time (&session->task->tv, session->cfg->clock_res));
#endif
msg_info ("%s", logbuf);
diff --git a/src/url.c b/src/url.c
index e560128f3..277b234b8 100644
--- a/src/url.c
+++ b/src/url.c
@@ -254,7 +254,7 @@ get_protocol (unsigned char *name, int namelen)
pname = protocol_backends[protocol].name;
pnamelen = strlen (pname);
minlen = MIN (pnamelen, namelen);
- compare = strncasecmp (pname, name, minlen);
+ compare = g_ascii_strncasecmp (pname, name, minlen);
if (compare == 0) {
if (pnamelen == namelen)
@@ -670,6 +670,14 @@ parse_uri (struct uri *uri, unsigned char *uristring, memory_pool_t * pool)
/* Assume http as default protocol */
if (!uri->protocollen || (uri->protocol = get_protocol (struri (uri), uri->protocollen)) == PROTOCOL_UNKNOWN) {
+ /* Make exception for numeric urls */
+ p = uri->string;
+ while (*p && (g_ascii_isalnum (*p) || *p == ':')) {
+ p ++;
+ }
+ if (*p == '\0') {
+ return URI_ERRNO_INVALID_PROTOCOL;
+ }
p = g_strconcat ("http://", uri->string, NULL);
uri->string = memory_pool_strdup (pool, p);
g_free (p);
@@ -912,12 +920,15 @@ url_parse_text (memory_pool_t * pool, struct worker_task *task, struct mime_text
if (new != NULL) {
g_strstrip (url_str);
rc = parse_uri (new, url_str, pool);
- if (rc != URI_ERRNO_EMPTY && rc != URI_ERRNO_NO_HOST) {
+ if (rc == URI_ERRNO_OK || rc == URI_ERRNO_NO_SLASHES || rc == URI_ERRNO_NO_HOST_SLASH) {
if (g_tree_lookup (is_html ? part->html_urls : part->urls, url_str) == NULL) {
g_tree_insert (is_html ? part->html_urls : part->urls, url_str, new);
task->urls = g_list_prepend (task->urls, new);
}
}
+ else {
+ msg_info ("extract of url '%s' failed: %s", url_str, url_strerror (rc));
+ }
}
}
}
diff --git a/src/util.c b/src/util.c
index 9a82a25f6..dc8569cdf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -778,18 +778,24 @@ resolve_stat_filename (memory_pool_t * pool, char *pattern, char *rcpt, char *fr
#ifdef HAVE_CLOCK_GETTIME
const char *
-calculate_check_time (struct timespec *begin, int resolution)
+calculate_check_time (struct timeval *tv, struct timespec *begin, int resolution)
#else
const char *
calculate_check_time (struct timeval *begin, int resolution)
#endif
{
- double diff;
- static char res[sizeof ("100000.000")];
- static char fmt[sizeof ("%.10f")];
+ double vdiff, diff;
+ static char res[64];
+ static char fmt[sizeof ("%.10f ms real, %.10f ms virtual")];
+ struct timeval tv_now;
+ if (gettimeofday (&tv_now, NULL) == -1) {
+ msg_warn ("gettimeofday failed: %s", strerror (errno));
+ }
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
+ diff = (tv_now.tv_sec - tv->tv_sec) * 1000. + /* Seconds */
+ (tv_now.tv_usec - tv->tv_usec) / 1000.; /* Microseconds */
#ifdef HAVE_CLOCK_PROCESS_CPUTIME_ID
clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts);
#elif defined(HAVE_CLOCK_VIRTUAL)
@@ -798,20 +804,17 @@ calculate_check_time (struct timeval *begin, int resolution)
clock_gettime (CLOCK_REALTIME, &ts);
#endif
- diff = (ts.tv_sec - begin->tv_sec) * 1000. + /* Seconds */
+ vdiff = (ts.tv_sec - begin->tv_sec) * 1000. + /* Seconds */
(ts.tv_nsec - begin->tv_nsec) / 1000000.; /* Nanoseconds */
#else
- struct timeval tv;
+ diff = (tv_now.tv_sec - begin->tv_sec) * 1000. + /* Seconds */
+ (tv_now.tv_usec - begin->tv_usec) / 1000.; /* Microseconds */
- if (gettimeofday (&tv, NULL) == -1) {
- msg_warn ("gettimeofday failed: %s", strerror (errno));
- }
- diff = (tv.tv_sec - begin->tv_sec) * 1000. + /* Seconds */
- (tv.tv_usec - begin->tv_usec) / 1000.; /* Microseconds */
+ vdiff = diff;
#endif
- sprintf (fmt, "%%.%df", resolution);
- snprintf (res, sizeof (res), fmt, diff);
+ sprintf (fmt, "%%.%dfms real, %%.%dfms virtual", resolution, resolution);
+ snprintf (res, sizeof (res), fmt, diff, vdiff);
return (const char *)res;
}
diff --git a/src/util.h b/src/util.h
index 89a430d52..b3e9338ab 100644
--- a/src/util.h
+++ b/src/util.h
@@ -65,7 +65,7 @@ int pidfile_remove(struct pidfh *pfh);
/* Replace %r with rcpt value and %f with from value, new string is allocated in pool */
char* resolve_stat_filename (memory_pool_t *pool, char *pattern, char *rcpt, char *from);
#ifdef HAVE_CLOCK_GETTIME
-const char* calculate_check_time (struct timespec *begin, int resolution);
+const char* calculate_check_time (struct timeval *tv, struct timespec *begin, int resolution);
#else
const char* calculate_check_time (struct timeval *begin, int resolution);
#endif
diff --git a/src/worker.c b/src/worker.c
index 13880bdfa..02077d5c9 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -430,11 +430,10 @@ construct_task (struct rspamd_worker *worker)
# else
clock_gettime (CLOCK_REALTIME, &new_task->ts);
# endif
-#else
+#endif
if (gettimeofday (&new_task->tv, NULL) == -1) {
msg_warn ("gettimeofday failed: %s", strerror (errno));
}
-#endif
io_tv.tv_sec = WORKER_IO_TIMEOUT;
io_tv.tv_usec = 0;
new_task->task_pool = memory_pool_new (memory_pool_get_size ());