You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by so...@apache.org on 2006/01/17 22:28:30 UTC

svn commit: r369922 - in /httpd/mod_smtpd/trunk/src: mod_smtpd.h smtp_core.c smtp_filters.c smtp_protocol.c smtp_util.c

Author: soc-rian
Date: Tue Jan 17 13:28:24 2006
New Revision: 369922

URL: http://svn.apache.org/viewcvs?rev=369922&view=rev
Log:
Changed header parsing and message handling. Headers are now eaten by
the header parser and only the body is stored. Also now the mandatory
"Received" header is added.


Modified:
    httpd/mod_smtpd/trunk/src/mod_smtpd.h
    httpd/mod_smtpd/trunk/src/smtp_core.c
    httpd/mod_smtpd/trunk/src/smtp_filters.c
    httpd/mod_smtpd/trunk/src/smtp_protocol.c
    httpd/mod_smtpd/trunk/src/smtp_util.c

Modified: httpd/mod_smtpd/trunk/src/mod_smtpd.h
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/mod_smtpd.h?rev=369922&r1=369921&r2=369922&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/mod_smtpd.h (original)
+++ httpd/mod_smtpd/trunk/src/mod_smtpd.h Tue Jan 17 13:28:24 2006
@@ -70,11 +70,6 @@
     SMTPD_PROTOCOL_ESMTP
 } smtpd_protocol_type;
 
-typedef enum {
-    SMTPD_HEADERS,
-    SMTPD_BODY
-} smtpd_body_pos;
-
 typedef struct smtpd_return_data {
     apr_pool_t *p;
     /* list of messages */
@@ -155,17 +150,6 @@
 SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_respond_oneline(smtpd_conn_rec *scr,
                                                          int code,
                                                          char *message);
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_respond_resetpos(smtpd_trans_rec *str);
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_body_resetpos(smtpd_trans_rec *str,
-                                                       smtpd_body_pos pos);
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_set_body_start(smtpd_trans_rec *str);
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_body_getline(smtpd_trans_rec *str,
-                                                      char *buffer,
-                                                      int buffer_size);
 
 SMTPD_DECLARE_NONSTD(ap_filter_t *)
          smtpd_add_input_filter_handle(ap_filter_rec_t *frec, void *ctx, 

Modified: httpd/mod_smtpd/trunk/src/smtp_core.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/smtp_core.c?rev=369922&r1=369921&r2=369922&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/smtp_core.c (original)
+++ httpd/mod_smtpd/trunk/src/smtp_core.c Tue Jan 17 13:28:24 2006
@@ -80,7 +80,7 @@
       "(\\\\.))*\"))@"
       /* Domain */
       "(([[:alnum:]]([[:alnum:]-]*[[:alnum:]])?)"
-      "(\\.([[:alnum:]]([[:alnum:]-]*[[:alnum:]])?))+))|([pP][oO][sS][mt]"
+      "(\\.([[:alnum:]]([[:alnum:]-]*[[:alnum:]])?))+))|([pP][oO][sS][tT][mM]"
       "[aA][sS][tT][eE][rR]))>"
       /* [Mail-parameters] */
       "( [[:alnum:]][-[:alnum:]]*(=[^ =]+)?)*$";

Modified: httpd/mod_smtpd/trunk/src/smtp_filters.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/smtp_filters.c?rev=369922&r1=369921&r2=369922&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/smtp_filters.c (original)
+++ httpd/mod_smtpd/trunk/src/smtp_filters.c Tue Jan 17 13:28:24 2006
@@ -102,28 +102,31 @@
     apreq_parser_t *rfc822_parser = my_ctx->rfc822_parser;
 
     /* if we already parsed our headers just pass to next filter */
-    if (my_ctx->headers_parsed)
+    if (my_ctx->headers_parsed) {
         return ap_get_brigade(f->next, b, mode, block, readbytes);
+    } else {
+        
+        /* eat up headers */
+        while(1) {
+            apr_brigade_cleanup(my_ctx->bb);
+            apr_brigade_cleanup(b);
+            rv = ap_get_brigade(f->next, my_ctx->bb, mode, block, readbytes);
+            if (rv != APR_SUCCESS)
+                return rv;
 
-    if (mode == AP_MODE_GETLINE) {
-        rv = ap_get_brigade(f->next, b, mode, block, readbytes);
-        if (rv != APR_SUCCESS)
-            return rv;
-
-        apr_brigade_cleanup(my_ctx->bb);
-        apreq_brigade_copy(my_ctx->bb, b);
-        rv = apreq_parser_run(rfc822_parser, str->headers, my_ctx->bb);
+            apreq_brigade_copy(b, my_ctx->bb);
+            rv = apreq_parser_run(rfc822_parser, str->headers, my_ctx->bb);
 
-        /* if we are done parsing, don't get another brigade
-           we'll pass the excess brigade to the caller */
-        if (rv == APR_SUCCESS) {
-            smtpd_set_body_start(str);
-            smtpd_run_headers_parsed(scr);
-            my_ctx->headers_parsed = 1;
+            /* if we are done parsing, don't get another brigade
+               we'll pass the excess brigade to the caller */
+            if (rv == APR_SUCCESS) {
+                break;
+            }
         }
-    } else {
-        return ap_get_brigade(f->next, b, mode, block, readbytes);
+
+        smtpd_run_headers_parsed(scr);
+        my_ctx->headers_parsed = 1;
+
+        return APR_SUCCESS;
     }
-    
-    return APR_SUCCESS;
 }

Modified: httpd/mod_smtpd/trunk/src/smtp_protocol.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/smtp_protocol.c?rev=369922&r1=369921&r2=369922&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/smtp_protocol.c (original)
+++ httpd/mod_smtpd/trunk/src/smtp_protocol.c Tue Jan 17 13:28:24 2006
@@ -613,6 +613,61 @@
     }
 }
 
+/* for debugging
+static int print_headers(void *rec, const char *key, 
+                  const char *value) {
+    smtpd_conn_rec *scr = rec;
+
+    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, scr->s,
+                 "(header) %s: %s", key, value);  
+    
+    return 1;
+}
+*/
+
+static void smtpd_add_received_header(smtpd_conn_rec *scr)
+{
+    apr_time_exp_t t;
+    smtpd_trans_rec *str = scr->transaction;
+    smtpd_svr_config_rec *pConfig =
+      ap_get_module_config(scr->s->module_config,
+                           &smtpd_module);
+    char time_string[80];
+    apr_size_t len;
+    apr_pool_t *p;
+    char *received_from;
+    char *protocol =
+      scr->protocol_type == SMTPD_PROTOCOL_SMTP ? "SMTP" : "ESMTP";
+    /* XXX: For now we mandatorily do a DNS lookup,
+       make it so we can do this according to the 
+       config rule "HostnameLookups" */
+    const char *remote_host = ap_get_remote_host(scr->c, NULL,
+                                                 REMOTE_DOUBLE_REV, NULL);
+    char *heloed;
+
+    apr_pool_create(&p, scr->p);
+
+    heloed = apr_psprintf(p, "(HELO %s) ", scr->helo);
+
+    apr_time_exp_lt(&t, apr_time_now());
+
+    apr_strftime(time_string, &len, sizeof(time_string),
+                 "%a, %d %b %Y %H:%M:%S %z", &t);
+
+    received_from = apr_psprintf(p, "from %s %s"
+                                 "(%s)\r\n"
+                                 "by %s (mod_smtpd/%s) with %s; %s",
+                                 remote_host, heloed,
+                                 scr->c->remote_ip,
+                                 pConfig->sId, "0.9", protocol,
+                                 time_string);
+
+    apr_table_add(str->headers, "Received",
+                  received_from);
+
+    apr_pool_destroy(p);
+}
+
 static int smtpd_handler_data(smtpd_conn_rec *scr, char *buffer,
                               smtpd_return_data *out_data)
 {
@@ -628,6 +683,7 @@
     apr_size_t len, total_data = 0;
     apr_bucket_brigade *bb;
     apr_bucket *e;
+    apreq_parser_t *rfc822_parser;
 
     if (buffer != NULL) {
         smtpd_respond_oneline(scr, 501, "Syntax: DATA");
@@ -721,9 +777,13 @@
     /* wait until there is no more data
        or until we have too much data */
     while (total_data < pConfig->max_data) {
-        ap_get_brigade(scr->transaction->input_filters, bb, AP_MODE_GETLINE,
-                       APR_BLOCK_READ, 0);
+        rv = ap_get_brigade(scr->transaction->input_filters, bb, AP_MODE_GETLINE,
+                            APR_BLOCK_READ, 0);
         
+        if (rv != APR_SUCCESS) {
+            goto done_spooling;
+        }
+
         for (e = APR_BRIGADE_FIRST(bb);
              ((e != APR_BRIGADE_SENTINEL(bb)) &&
               (total_data < pConfig->max_data));
@@ -751,14 +811,7 @@
  done_spooling:
     apr_file_flush(tfp);
 
-    /*
-      XXX: Qpsmtpd code to add the Received Header, will get refactored
-      $header->add("Received", "from ".$self->connection->remote_info
-      ." (HELO ".$self->connection->hello_host . ") (".$self->connection->remote_ip
-      . ")\n  $authheader  by ".$self->config('me')." (qpsmtpd/".$self->version
-      .") with $smtp; ". (strftime('%a, %d %b %Y %H:%M:%S %z', localtime)),
-      0);
-    */
+    smtpd_add_received_header(scr);
 
     switch(smtpd_run_data_post(scr, out_data)) {
     case SMTPD_DONE:

Modified: httpd/mod_smtpd/trunk/src/smtp_util.c
URL: http://svn.apache.org/viewcvs/httpd/mod_smtpd/trunk/src/smtp_util.c?rev=369922&r1=369921&r2=369922&view=diff
==============================================================================
--- httpd/mod_smtpd/trunk/src/smtp_util.c (original)
+++ httpd/mod_smtpd/trunk/src/smtp_util.c Tue Jan 17 13:28:24 2006
@@ -154,31 +154,6 @@
     return APR_SUCCESS;
 }
 
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_body_resetpos(smtpd_trans_rec *str,
-                                                       smtpd_body_pos pos)
-{
-    apr_off_t offset = (pos == SMTPD_HEADERS) ? 0 : str->body_offset;
-    return apr_file_seek(str->tfp, APR_SET, &offset);
-}
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_set_body_start(smtpd_trans_rec *str)
-{
-    apr_off_t pos = 0;
-    apr_status_t rv;
-    rv = apr_file_seek(str->tfp, APR_CUR, &pos);
-    if (rv != APR_SUCCESS)
-        return rv;
-    str->body_offset = pos;
-    return rv;
-}
-
-SMTPD_DECLARE_NONSTD(apr_status_t) smtpd_body_getline(smtpd_trans_rec *str,
-                                                      char *buffer,
-                                                      int buffer_size)
-{
-    return apr_file_gets(buffer, buffer_size, str->tfp);
-}
-
 #define INSERT_BEFORE(f, before_this) ((before_this) == NULL \
                            || (before_this)->frec->ftype >= (f)->frec->ftype \
                            || (before_this)->r != (f)->r)