Logging: millisecond time on 'no MAIL' lines. Bug 2102
[exim.git] / src / src / smtp_in.c
index 5ff1b7f32d7e9cf50e3fad89431e90d69534ef7f..48437c3808994c78182fdc68ad958d35c4c99760 100644 (file)
@@ -339,8 +339,8 @@ int fd, rc;
 fd_set fds;
 struct timeval tzero;
 
-if (tls_in.active >= 0 && tls_could_read())
 return FALSE;
+if (tls_in.active >= 0)
return !tls_could_read();
 
 if (smtp_inptr < smtp_inend)
   return FALSE;
@@ -1795,15 +1795,33 @@ for (i = 0; i < smtp_ch_index; i++)
   sep = US",";
   }
 
-if (s != NULL) s[ptr] = 0; else s = US"";
+if (s) s[ptr] = 0; else s = US"";
 log_write(0, LOG_MAIN, "no MAIL in SMTP connection from %s D=%s%s",
-  host_and_ident(FALSE),
-  readconf_printtime( (int) ((long)time(NULL) - (long)smtp_connection_start)),
-  s);
+  host_and_ident(FALSE), string_timesince(&smtp_connection_start), s);
+}
+
+
+/* Return list of recent smtp commands */
+
+uschar *
+smtp_cmd_hist(void)
+{
+uschar * list = NULL;
+int size = 0, len = 0, i;
+
+for (i = smtp_ch_index; i < SMTP_HBUFF_SIZE; i++)
+  if (smtp_connection_had[i] != SCH_NONE)
+    list = string_append_listele(list, &size, &len, ',',
+      smtp_names[smtp_connection_had[i]]);
+for (i = 0; i < smtp_ch_index; i++)
+  list = string_append_listele(list, &size, &len, ',',
+    smtp_names[smtp_connection_had[i]]);
+return list ? list : US"";
 }
 
 
 
+
 /*************************************************
 *   Check HELO line and set sender_helo_name     *
 *************************************************/
@@ -2333,7 +2351,7 @@ uschar *user_msg, *log_msg;
 uschar *code, *esc;
 uschar *p, *s, *ss;
 
-smtp_connection_start = time(NULL);
+gettimeofday(&smtp_connection_start, NULL);
 for (smtp_ch_index = 0; smtp_ch_index < SMTP_HBUFF_SIZE; smtp_ch_index++)
   smtp_connection_had[smtp_ch_index] = SCH_NONE;
 smtp_ch_index = 0;
@@ -2599,10 +2617,7 @@ if (!sender_host_unknown)
             Ustrcat(p, "[ ");
             p += 2;
             for (i = 0; i < opt[1]; i++)
-              {
-              sprintf(CS p, "%2.2x ", opt[i]);
-              p += 3;
-              }
+              p += sprintf(CS p, "%2.2x ", opt[i]);
             *p++ = ']';
             }
           opt += opt[1];
@@ -3011,7 +3026,7 @@ if (rcpt_in_progress)
   rcpt_in_progress = FALSE;
   }
 
-/* Not output the message, splitting it up into multiple lines if necessary.
+/* Now output the message, splitting it up into multiple lines if necessary.
 We only handle pipelining these responses as far as nonfinal/final groups,
 not the whole MAIL/RCPT/DATA response set. */
 
@@ -4230,26 +4245,34 @@ while (done <= 0)
        auth_instance *au;
        BOOL first = TRUE;
        for (au = auths; au; au = au->next)
-         if (au->server && (au->advertise_condition == NULL ||
-             expand_check_condition(au->advertise_condition, au->name,
-             US"authenticator")))
+         {
+         au->advertised = FALSE;
+         if (au->server)
            {
-           int saveptr;
-           if (first)
+           DEBUG(D_auth+D_expand) debug_printf_indent(
+             "Evaluating advertise_condition for %s athenticator\n",
+             au->public_name);
+           if (  !au->advertise_condition
+              || expand_check_condition(au->advertise_condition, au->name,
+                     US"authenticator")
+              )
              {
-             s = string_catn(s, &size, &ptr, smtp_code, 3);
-             s = string_catn(s, &size, &ptr, US"-AUTH", 5);
-             first = FALSE;
-             auth_advertised = TRUE;
+             int saveptr;
+             if (first)
+               {
+               s = string_catn(s, &size, &ptr, smtp_code, 3);
+               s = string_catn(s, &size, &ptr, US"-AUTH", 5);
+               first = FALSE;
+               auth_advertised = TRUE;
+               }
+             saveptr = ptr;
+             s = string_catn(s, &size, &ptr, US" ", 1);
+             s = string_cat (s, &size, &ptr, au->public_name);
+             while (++saveptr < ptr) s[saveptr] = toupper(s[saveptr]);
+             au->advertised = TRUE;
              }
-           saveptr = ptr;
-           s = string_catn(s, &size, &ptr, US" ", 1);
-           s = string_cat (s, &size, &ptr, au->public_name);
-           while (++saveptr < ptr) s[saveptr] = toupper(s[saveptr]);
-           au->advertised = TRUE;
            }
-         else
-           au->advertised = FALSE;
+         }
 
        if (!first) s = string_catn(s, &size, &ptr, US"\r\n", 2);
        }