Rian Hunter <[EMAIL PROTECTED]> writes: > You can checkout this code out from: > http://svn.apache.org/repos/asf/httpd/mod_smtpd/trunk/
Very cool, thanks! I had some trouble compiling it, and I noticed you're using // comments alot. Here are two patches for that.
diff -pur trunk/.svn/entries trunk-00/.svn/entries --- trunk/.svn/entries 2005-08-14 01:17:03.000000000 -0400 +++ trunk-00/.svn/entries 2005-08-14 01:11:47.000000000 -0400 @@ -58,7 +58,7 @@ <entry committed-rev="232339" name="smtp.h" - text-time="2005-08-14T05:17:00.000000Z" + text-time="2005-08-14T05:11:42.000000Z" committed-date="2005-08-12T17:49:24.266873Z" checksum="c8519c3c6a4ab00a5fbdec40f7d0aa8a" last-author="soc-rian" @@ -85,7 +85,7 @@ <entry committed-rev="232410" name="smtp_core.c" - text-time="2005-08-14T05:17:03.000000Z" + text-time="2005-08-14T05:11:44.000000Z" committed-date="2005-08-13T00:38:27.597147Z" checksum="2c1c6795c34b54aa910547906d68529f" last-author="soc-rian" diff -pur trunk/smtp.h trunk-00/smtp.h --- trunk/smtp.h 2005-08-14 01:17:00.000000000 -0400 +++ trunk-00/smtp.h 2005-08-14 01:12:05.000000000 -0400 @@ -49,7 +49,7 @@ extern "C" { smtpd_clear_request_rec(smtpd_request_rec *); apr_hash_t * - smtpd_get_handlers(); + smtpd_get_handlers(void); HANDLER_DECLARE(ehlo); HANDLER_DECLARE(helo); diff -pur trunk/smtp_core.c trunk-00/smtp_core.c --- trunk/smtp_core.c 2005-08-14 01:17:03.000000000 -0400 +++ trunk-00/smtp_core.c 2005-08-14 01:12:05.000000000 -0400 @@ -345,9 +345,10 @@ register_hooks (apr_pool_t *p) // register connection processor ap_hook_process_connection(process_smtp_connection, NULL, NULL, APR_HOOK_MIDDLE); + /* APR_OPTIONAL_HOOK(smtpd, queue, default_queue, NULL, NULL, APR_HOOK_LAST); APR_OPTIONAL_HOOK(smtpd, rcpt, default_rcpt, NULL, NULL, APR_HOOK_LAST); - + */ smtpd_handlers = apr_hash_make(p); smtpd_register_handler("EHLO", HANDLER_FUNC(ehlo), "ehlo", NULL, p);
diff -pur trunk-00/.svn/entries trunk-01/.svn/entries --- trunk-00/.svn/entries 2005-08-14 01:11:47.000000000 -0400 +++ trunk-01/.svn/entries 2005-08-14 00:42:43.000000000 -0400 @@ -49,7 +49,7 @@ <entry committed-rev="232410" name="smtp_protocol.c" - text-time="2005-08-14T05:11:47.000000Z" + text-time="2005-08-14T04:42:43.000000Z" committed-date="2005-08-13T00:38:27.597147Z" checksum="7db293424073248e068c105282e570fe" last-author="soc-rian" @@ -58,7 +58,7 @@ <entry committed-rev="232339" name="smtp.h" - text-time="2005-08-14T05:11:42.000000Z" + text-time="2005-08-14T04:42:36.000000Z" committed-date="2005-08-12T17:49:24.266873Z" checksum="c8519c3c6a4ab00a5fbdec40f7d0aa8a" last-author="soc-rian" @@ -76,7 +76,7 @@ <entry committed-rev="232410" name="mod_smtpd.h" - text-time="2005-08-14T05:11:39.000000Z" + text-time="2005-08-14T04:42:29.000000Z" committed-date="2005-08-13T00:38:27.597147Z" checksum="8589f148187590c31a9a05c7bc9bc860" last-author="soc-rian" @@ -85,7 +85,7 @@ <entry committed-rev="232410" name="smtp_core.c" - text-time="2005-08-14T05:11:44.000000Z" + text-time="2005-08-14T04:42:40.000000Z" committed-date="2005-08-13T00:38:27.597147Z" checksum="2c1c6795c34b54aa910547906d68529f" last-author="soc-rian" diff -pur trunk-00/mod_smtpd.h trunk-01/mod_smtpd.h --- trunk-00/mod_smtpd.h 2005-08-14 01:11:39.000000000 -0400 +++ trunk-01/mod_smtpd.h 2005-08-14 00:47:42.000000000 -0400 @@ -26,7 +26,7 @@ extern "C" { #endif - // Current version of the Plugin interface + /* Current version of the Plugin interface */ #define SMTPD_PLUGIN_VERSION 20050414 #if !defined(WIN32) @@ -80,33 +80,33 @@ extern "C" { conn_rec *c; server_rec *s; - // spooled data file pointer + /* spooled data file pointer */ apr_file_t *tfp; - // where are we in the current transaction + /* where are we in the current transaction */ smtpd_request_state state_vector; - // is this esmtp or smtp - // by default smtp + /* is this esmtp or smtp */ + /* by default smtp */ smtpd_protocol_type extended; - // current max index of the extension hash + /* current max index of the extension hash */ int e_index; apr_hash_t *extensions; - // string of who this mail is from + /* string of who this mail is from */ char *mail_from; - // current max index of the rcpt_to hash + /* current max index of the rcpt_to hash */ int r_index; apr_hash_t *rcpt_to; - // hostname we were helo'd with + /* hostname we were helo'd with */ char *helo; } smtpd_request_rec; - // public + /* public */ SMTPD_DECLARE_NONSTD(smtpd_request_rec *) smtpd_get_request_rec(request_rec *r); diff -pur trunk-00/smtp.h trunk-01/smtp.h --- trunk-00/smtp.h 2005-08-14 01:12:05.000000000 -0400 +++ trunk-01/smtp.h 2005-08-14 00:48:06.000000000 -0400 @@ -22,7 +22,7 @@ extern "C" { #endif - // SMTP handlers registration + /* SMTP handlers registration */ #define HANDLER_PROTOTYPE request_rec *r, char *buffer, smtpd_return_data *in_data, void *data #define HANDLER_FUNC(name) smtpd_handler_##name diff -pur trunk-00/smtp_core.c trunk-01/smtp_core.c --- trunk-00/smtp_core.c 2005-08-14 01:12:05.000000000 -0400 +++ trunk-01/smtp_core.c 2005-08-14 00:54:07.000000000 -0400 @@ -44,86 +44,86 @@ module AP_MODULE_DECLARE_DATA smtpd_modu static apr_hash_t *smtpd_handlers; -// Implement 'smtpd_run_unrecognized_command'. +/* Implement 'smtpd_run_unrecognized_command'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, unrecognized_command, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_connect'. +/* Implement 'smtpd_run_connect'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, connect, (request_rec *r, smtpd_return_data *in), (r, in), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_reset_transaction'. +/* Implement 'smtpd_run_reset_transaction'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, reset_transaction, (request_rec *r), (r), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_helo'. +/* Implement 'smtpd_run_helo'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, helo, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_ehlo'. +/* Implement 'smtpd_run_ehlo'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, ehlo, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_mail'. +/* Implement 'smtpd_run_mail'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, mail, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_rcpt'. +/* Implement 'smtpd_run_rcpt'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, rcpt, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_vrfy'. +/* Implement 'smtpd_run_vrfy'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, vrfy, (request_rec *r, smtpd_return_data *in, char *str), (r, in, str), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_quit'. +/* Implement 'smtpd_run_quit'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, quit, (request_rec *r, smtpd_return_data *in), (r, in), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_data'. +/* Implement 'smtpd_run_data'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, data, (request_rec *r, smtpd_return_data *in), (r, in), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_data_post'. +/* Implement 'smtpd_run_data_post'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, data_post, (request_rec *r, smtpd_return_data *in), (r, in), SMTPD_DECLINED, SMTPD_DECLINED); -// Implement 'smtpd_run_data_queue'. +/* Implement 'smtpd_run_data_queue'. */ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(smtpd, SMTPD, smtpd_retcode, queue, (request_rec *r, smtpd_return_data *in), (r, in), SMTPD_DECLINED, SMTPD_DECLINED); -// public methods -// functions other modules can use +/* public methods */ +/* functions other modules can use */ -// accessor +/* accessor */ SMTPD_DECLARE_NONSTD(smtpd_request_rec *) smtpd_get_request_rec(request_rec *r) { return ap_get_module_config(r->request_config, &smtpd_module); } -// should be called at smtpd_hook_connect +/* should be called at smtpd_hook_connect */ SMTPD_DECLARE_NONSTD(void) smtpd_register_extension(smtpd_request_rec *sr, const char *line) { @@ -134,19 +134,20 @@ smtpd_register_extension(smtpd_request_r (sr->e_index)++; } -// how to reset the transaction +/* how to reset the transaction */ SMTPD_DECLARE_NONSTD(void) smtpd_reset_transaction(request_rec *r) { - // REVIEW: don't know whether to run clear request first - // then run reset hooks, or run reset hooks then clear request - // depends on whether hooks want to save info before it gets cleared out - // or if they want to overwrite default values in the request rec - smtpd_run_reset_transaction(r); + /* REVIEW: don't know whether to run clear request first + * then run reset hooks, or run reset hooks then clear request + * depends on whether hooks want to save info before it gets cleared out + * or if they want to overwrite default values in the request rec + * smtpd_run_reset_transaction(r); + */ smtpd_clear_request_rec(smtpd_get_request_rec(r)); } -// friend methods -// only our sources can call these +/* friend methods */ +/* only our sources can call these */ void smtpd_clear_request_rec(smtpd_request_rec *sr) { @@ -167,10 +168,10 @@ smtpd_get_handlers() { return smtpd_handlers; } -// private methods -// only used in this file +/* private methods */ +/* only used in this file */ -// can overwrite currently registered handlers +/* can overwrite currently registered handlers */ static void smtpd_register_handler(char *key, smtpd_handler *func, const char *help_text, void *data, apr_pool_t *p) @@ -186,7 +187,7 @@ smtpd_register_handler(char *key, smtpd_ apr_hash_set(smtpd_handlers, dupkey, APR_HASH_KEY_STRING, hand); } -// Creates the main request record for the connection +/* Creates the main request record for the connection */ static request_rec * smtpd_create_request(conn_rec *conn) { @@ -212,7 +213,7 @@ smtpd_create_request(conn_rec *conn) r->err_headers_out = apr_table_make(r->pool, 5); r->notes = apr_table_make(r->pool, 5); - // Must be set before we run create request hook + /* Must be set before we run create request hook */ r->request_config = ap_create_request_config(r->pool); r->proto_output_filters = conn->output_filters; @@ -232,7 +233,7 @@ smtpd_create_request(conn_rec *conn) apr_socket_t *csd=((core_net_rec *)r->input_filters->ctx)->client_socket; apr_socket_timeout_set(csd, APR_INT64_C(10000000000000)); - // create custom smtpd rec + /* create custom smtpd rec */ sr = apr_pcalloc(r->pool, sizeof(*sr)); apr_pool_create(&sp, r->pool); @@ -246,7 +247,7 @@ smtpd_create_request(conn_rec *conn) return r; } -// process connection hook +/* process connection hook */ static int process_smtp_connection(conn_rec *c) { @@ -267,7 +268,7 @@ process_smtp_connection(conn_rec *c) return OK; } -// creates server config +/* creates server config */ static void * smtpd_create_server_config(apr_pool_t *p, server_rec *s) { @@ -280,7 +281,7 @@ smtpd_create_server_config(apr_pool_t *p return pConfig; } -// sets protocol status in server config +/* sets protocol status in server config */ static const char * set_protocol_status(cmd_parms *cmd, void *struct_ptr, @@ -294,7 +295,7 @@ set_protocol_status(cmd_parms *cmd, return NULL; } -// sets server id string in server config +/* sets server id string in server config */ static const char * set_id_string(cmd_parms *cmd, void *struct_ptr, @@ -309,7 +310,7 @@ set_id_string(cmd_parms *cmd, return NULL; } -// sets server id string in server config +/* sets server id string in server config */ static const char * set_max_data_size(cmd_parms *cmd, void *struct_ptr, @@ -338,11 +339,11 @@ static const command_rec smtpd_cmds[] = { NULL } }; -// registers httpd hooks +/* registers httpd hooks */ static void register_hooks (apr_pool_t *p) { - // register connection processor +/* register connection processor */ ap_hook_process_connection(process_smtp_connection, NULL, NULL, APR_HOOK_MIDDLE); /* @@ -364,10 +365,10 @@ register_hooks (apr_pool_t *p) module AP_MODULE_DECLARE_DATA smtpd_module = { STANDARD20_MODULE_STUFF, - NULL, // create per-directory config structure - NULL, // merge per-directory config structures - smtpd_create_server_config, // create per-server config structure - NULL, // merge per-server config structures - smtpd_cmds, // command apr_table_t - register_hooks // register hooks + NULL, /* create per-directory config structure */ + NULL, /* merge per-directory config structures */ + smtpd_create_server_config, /* create per-server config structure */ + NULL, /* merge per-server config structures */ + smtpd_cmds, /* command apr_table_t */ + register_hooks /* register hooks */ }; diff -pur trunk-00/smtp_protocol.c trunk-01/smtp_protocol.c --- trunk-00/smtp_protocol.c 2005-08-14 01:11:47.000000000 -0400 +++ trunk-01/smtp_protocol.c 2005-08-14 00:59:18.000000000 -0400 @@ -89,7 +89,7 @@ process_smtp_connection_internal(request handle_func = apr_hash_get(handlers, command, APR_HASH_KEY_STRING); in_data.msg = NULL; - // command not recognized + /* command not recognized */ if (handle_func == NULL) { switch(smtpd_run_unrecognized_command(r, &in_data, command)) { case SMTPD_DENY: @@ -114,7 +114,7 @@ process_smtp_connection_internal(request } end: - // flush any output we may have before disconnecting + /* flush any output we may have before disconnecting */ ap_rflush(r); return; } @@ -148,10 +148,10 @@ HANDLER_DECLARE(ehlo) { break; } - // default behavior: + /* default behavior: */ - // RFC 2821 states that when ehlo or helo is received, reset - // state + /* RFC 2821 states that when ehlo or helo is received, reset */ + /* state */ smtpd_reset_transaction(r); if ((sr->helo = apr_pstrdup(sr->p, buffer)) == NULL) { @@ -160,7 +160,7 @@ HANDLER_DECLARE(ehlo) { goto end; } - // print out extension + /* print out extension */ ext = apr_hash_get(sr->extensions, &i, sizeof(i)); retval = 250; @@ -192,7 +192,7 @@ HANDLER_DECLARE(helo) { smtpd_request_rec *sr = smtpd_get_request_rec(r); int retval = 0; - // bad syntax + /* bad syntax */ if (buffer[0] == '\0') { ap_rprintf(r, "%d %s\r\n", 501, "Syntax: HELO hostname"); retval = 501; @@ -218,11 +218,11 @@ HANDLER_DECLARE(helo) { break; } - // RFC 2821 states that when ehlo or helo is received, reset - // state + /* RFC 2821 states that when ehlo or helo is received, reset */ + /* state */ smtpd_reset_transaction(r); - // out of memory, close connection + /* out of memory, close connection */ if ((sr->helo = apr_pstrdup(sr->p, buffer)) == NULL) { ap_rprintf(r, "%d %s\r\n", 421, "Error: Internal"); retval = 0; @@ -243,14 +243,14 @@ HANDLER_DECLARE(mail) { char *loc; int retval = 0; - // already got mail + /* already got mail */ if (sr->state_vector == SMTPD_STATE_GOT_MAIL) { ap_rprintf(r, "%d %s\r\n", 503, "Error: Nested MAIL command"); retval = 503; goto end; } - // bad syntax + /* bad syntax */ if ((loc = ap_strcasestr(buffer, "from:")) == NULL) { ap_rprintf(r, "%d %s\r\n", 501, "Syntax: MAIL FROM:<address>"); retval = 501; @@ -292,7 +292,7 @@ HANDLER_DECLARE(mail) { } goto end; case SMTPD_DENY_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, r->server, "deny mail from %s (%s)", loc, @@ -304,7 +304,7 @@ HANDLER_DECLARE(mail) { } goto end; case SMTPD_DENYSOFT_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, r->server, "denysoft mail from %s (%s)", loc, @@ -319,9 +319,9 @@ HANDLER_DECLARE(mail) { break; } - // default handling + /* default handling */ - // out of memory, close connection + /* out of memory, close connection */ if ((sr->mail_from = apr_pstrdup(sr->p, loc)) == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Out Of Memory"); ap_rprintf(r, "%d %s\r\n", 421, "Error: Internal"); @@ -345,7 +345,7 @@ HANDLER_DECLARE(rcpt) { char *allocated_string; int retval = 0; - // need mail first + /* need mail first */ if ((sr->state_vector != SMTPD_STATE_GOT_MAIL) && (sr->state_vector != SMTPD_STATE_GOT_RCPT)) { ap_rprintf(r, "%d %s\r\n", 503, "Error: need MAIL command"); @@ -353,7 +353,7 @@ HANDLER_DECLARE(rcpt) { goto end; } - // bad syntax + /* bad syntax */ if ((loc = ap_strcasestr(buffer, "to:")) == NULL) { ap_rprintf(r, "%d %s\r\n", 501, "Syntax: RCPT TO:<address>"); retval = 501; @@ -383,7 +383,7 @@ HANDLER_DECLARE(rcpt) { } goto end; case SMTPD_DENY_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, r->server, "delivery denied (%s)", @@ -392,7 +392,7 @@ HANDLER_DECLARE(rcpt) { "delivery denied"); goto end; case SMTPD_DENYSOFT_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, r->server, "delivery denied (%s)", @@ -400,7 +400,7 @@ HANDLER_DECLARE(rcpt) { ap_rprintf(r, "%d %s\r\n", 450, in_data->msg ? in_data->msg : "relaying temporarily denied"); goto end; - case SMTPD_OK: // recipient is okay + case SMTPD_OK: /* recipient is okay */ break; default: retval = 450; @@ -409,7 +409,7 @@ HANDLER_DECLARE(rcpt) { goto end; } - // add a recipient + /* add a recipient */ if ((allocated_string = apr_pstrdup(sr->p, loc))) { apr_hash_set(sr->rcpt_to, &(sr->r_index), @@ -421,7 +421,7 @@ HANDLER_DECLARE(rcpt) { retval = 250; } else { ap_rprintf(r, "%d %s\r\n", 421, "Error: Internal"); - // out of memory close connection + /* out of memory close connection */ retval = 0; } @@ -450,26 +450,26 @@ HANDLER_DECLARE(data) { goto end; case SMTPD_DENY: retval = 554; - // REVIEW: should we reset state here? - // smtpd_clear_request_rec(sr); + /* REVIEW: should we reset state here? */ + /* smtpd_clear_request_rec(sr); */ ap_rprintf(r, "%d %s\r\n", 554, in_data->msg ? in_data->msg : "Message denied"); goto end; case SMTPD_DENYSOFT: retval = 451; - // REVIEW: should we reset state here? - // smtpd_clear_request_rec(sr); + /* REVIEW: should we reset state here? */ + /* smtpd_clear_request_rec(sr); */ ap_rprintf(r, "%d %s\r\n", 451, in_data->msg ? in_data->msg : "Message denied temporarily"); goto end; case SMTPD_DENY_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_rprintf(r, "%d %s\r\n", 554, in_data->msg ? in_data->msg : "Message denied"); goto end; case SMTPD_DENYSOFT_DISCONNECT: - // zero to disconnect + /* zero to disconnect */ retval = 0; ap_rprintf(r, "%d %s\r\n", 451, in_data->msg ? in_data->msg : "Message denied temporarily"); @@ -497,14 +497,14 @@ HANDLER_DECLARE(data) { if (rv != APR_SUCCESS) { ap_rprintf(r, "%d %s\r\n", 421, "Error: Internal"); - // file error close connection + /* file error close connection */ retval = 0; goto end; } - // just wait until we get the line with a dot. - // or until we can't read anymore. - // or until we have too much data + /* just wait until we get the line with a dot. */ + /* or until we can't read anymore. */ + /* or until we have too much data */ while ((ap_rgetline(&buffer, BUFFER_STR_LEN, &len, r, 0, bb) == APR_SUCCESS) && (strcmp(buffer, ".")) && @@ -596,7 +596,7 @@ HANDLER_DECLARE(quit) { ap_rflush(r); } - // zero to disconnect + /* zero to disconnect */ return 0; } @@ -615,7 +615,7 @@ HANDLER_DECLARE(vrfy) { ap_rprintf(r, "%d %s\r\n", 554, in_data->msg ? in_data->msg : "Address denied"); break; - case SMTPD_OK: // user is okay + case SMTPD_OK: /* user is okay */ retval = 250; ap_rprintf(r, "%d %s\r\n", 250, in_data->msg ? in_data->msg : "Address okay");
-- Joe Schaefer