]> source.dussan.org Git - rspamd.git/commitdiff
* Fix detection of numeric urls (reported by citrin)
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 5 Jul 2010 13:48:20 +0000 (17:48 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 5 Jul 2010 13:48:20 +0000 (17:48 +0400)
* Write real time of message's scan to log (not only virtual)

src/main.h
src/plugins/surbl.c
src/protocol.c
src/smtp.c
src/url.c
src/util.c
src/util.h
src/worker.c

index 233fd6159b8d3c9c0c48ce04ea4b8c4e29187756..defa25c0da2d8ced68b0a23042d6174d3cc745b2 100644 (file)
@@ -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                                      */
index 8c9d2ccb08f07eaae84d7e102f27f907b1ddbe6a..f50bd8976044e6565ac90429cf466cc7d31501db 100644 (file)
@@ -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 {
index 98d68bf129934dace92f009ce05cf21c6a8ced15..76627e15e28f4a12d6ffc986dc8b8d6297174e56 100644 (file)
@@ -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
 }
index 8f3411b027b2b9ba9168c5662f2f29d346c9ff3f..885a1f681c6f0d5bd964a3168fbadfbe3c915a4a 100644 (file)
@@ -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);
index e560128f347146b9f73198ecd99ab84348a7afb5..277b234b86cb9b13ec374b5ec57bb0051fca7dff 100644 (file)
--- 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));
+                                                       }
                                                }
                                        }
                                }
index 9a82a25f65aefbfaa139d7069ff8d56cf4fdeefe..dc8569cdf75cf7f655a3d956f89695ac09871182 100644 (file)
@@ -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;
 }
index 89a430d52993dbcd2821e09eeb5e7f8caa2fb112..b3e9338abe196848cdeff7f14ddecfeee19f7780 100644 (file)
@@ -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
index 13880bdfa08b821e690568931a0e26516c997188..02077d5c9df8f362e86514e158addac78877f99e 100644 (file)
@@ -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 ());