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 */
/* 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 {
}
}
#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
}
}
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);
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)
/* 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);
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));
+ }
}
}
}
#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)
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;
}
/* 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
# 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 ());