From: Stephan Bosch Date: Wed, 8 Apr 2020 20:05:57 +0000 (+0200) Subject: lib-smtp: Reformat test-smtp-client-errors.c. X-Git-Tag: 2.3.13~654 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=10667b6a9d1b07119f3a37e7c2054c75760e338a;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: Reformat test-smtp-client-errors.c. --- diff --git a/src/lib-smtp/test-smtp-client-errors.c b/src/lib-smtp/test-smtp-client-errors.c index db0a43987e..83c001c574 100644 --- a/src/lib-smtp/test-smtp-client-errors.c +++ b/src/lib-smtp/test-smtp-client-errors.c @@ -49,8 +49,8 @@ struct server_connection { }; typedef void (*test_server_init_t)(unsigned int index); -typedef bool (*test_client_init_t) - (const struct smtp_client_settings *client_set); +typedef bool +(*test_client_init_t)(const struct smtp_client_settings *client_set); typedef void (*test_dns_init_t)(void); /* @@ -74,10 +74,11 @@ static unsigned int server_pids_count = 0; static struct connection_list *server_conn_list; static unsigned int server_index; static void (*test_server_input)(struct server_connection *conn); -static int (*test_server_input_line)(struct server_connection *conn, - const char *line); -static int (*test_server_input_data)(struct server_connection *conn, - const unsigned char *data, size_t size); +static int +(*test_server_input_line)(struct server_connection *conn, const char *line); +static int +(*test_server_input_data)(struct server_connection *conn, + const unsigned char *data, size_t size); static int (*test_server_init)(struct server_connection *conn); static void (*test_server_deinit)(struct server_connection *conn); @@ -91,22 +92,19 @@ static struct smtp_client *smtp_client = NULL; /* server */ static void test_server_run(unsigned int index); -static void -server_connection_deinit(struct server_connection **_conn); +static void server_connection_deinit(struct server_connection **_conn); /* client */ -static void -test_client_defaults(struct smtp_client_settings *smtp_set); +static void test_client_defaults(struct smtp_client_settings *smtp_set); static void test_client_deinit(void); /* test*/ -static void test_run_client_server( - const struct smtp_client_settings *client_set, - test_client_init_t client_test, - test_server_init_t server_test, - unsigned int server_tests_count, - test_dns_init_t dns_test) - ATTR_NULL(3); +static void +test_run_client_server(const struct smtp_client_settings *client_set, + test_client_init_t client_test, + test_server_init_t server_test, + unsigned int server_tests_count, + test_dns_init_t dns_test) ATTR_NULL(3); /* * Unconfigured SSL @@ -115,14 +113,12 @@ static void test_run_client_server( /* server */ static void -test_server_unconfigured_ssl_input( - struct server_connection *conn ATTR_UNUSED) +test_server_unconfigured_ssl_input(struct server_connection *conn ATTR_UNUSED) { /* nothing */ } -static void -test_server_unconfigured_ssl(unsigned int index) +static void test_server_unconfigured_ssl(unsigned int index) { sleep(100); test_server_input = test_server_unconfigured_ssl_input; @@ -137,7 +133,7 @@ struct _unconfigured_ssl { static void test_client_unconfigured_ssl_reply(const struct smtp_reply *reply, - void *context) + void *context) { struct _unconfigured_ssl *ctx = (struct _unconfigured_ssl *)context; @@ -165,17 +161,17 @@ test_client_unconfigured_ssl(const struct smtp_client_settings *client_set) smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, test_client_unconfigured_ssl_reply, ctx); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); - smtp_client_connection_connect(sconn, - test_client_unconfigured_ssl_reply, ctx); + smtp_client_connection_connect( + sconn, test_client_unconfigured_ssl_reply, ctx); return TRUE; } @@ -190,8 +186,8 @@ static void test_unconfigured_ssl(void) test_begin("unconfigured ssl"); test_run_client_server(&smtp_client_set, - test_client_unconfigured_ssl, - test_server_unconfigured_ssl, 1, NULL); + test_client_unconfigured_ssl, + test_server_unconfigured_ssl, 1, NULL); test_end(); } @@ -208,8 +204,7 @@ test_server_unconfigured_ssl_abort_input( /* nothing */ } -static void -test_server_unconfigured_ssl_abort(unsigned int index) +static void test_server_unconfigured_ssl_abort(unsigned int index) { sleep(100); test_server_input = test_server_unconfigured_ssl_abort_input; @@ -223,7 +218,8 @@ struct _unconfigured_ssl_abort { }; static void -test_client_unconfigured_ssl_abort_reply1(const struct smtp_reply *reply, +test_client_unconfigured_ssl_abort_reply1( + const struct smtp_reply *reply, struct _unconfigured_ssl_abort *ctx ATTR_UNUSED) { if (debug) @@ -234,7 +230,7 @@ test_client_unconfigured_ssl_abort_reply1(const struct smtp_reply *reply, static void test_client_unconfigured_ssl_abort_reply2(const struct smtp_reply *reply, - struct _unconfigured_ssl_abort *ctx) + struct _unconfigured_ssl_abort *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -260,22 +256,22 @@ test_client_unconfigured_ssl_abort( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_unconfigured_ssl_abort_reply1, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_unconfigured_ssl_abort_reply1, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); smtp_client_command_abort(&scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "127.0.0.1", bind_ports[0], SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_unconfigured_ssl_abort_reply2, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_unconfigured_ssl_abort_reply2, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -292,8 +288,8 @@ static void test_unconfigured_ssl_abort(void) test_begin("unconfigured ssl abort"); test_run_client_server(&smtp_client_set, - test_client_unconfigured_ssl_abort, - test_server_unconfigured_ssl_abort, 1, NULL); + test_client_unconfigured_ssl_abort, + test_server_unconfigured_ssl_abort, 1, NULL); test_end(); } @@ -309,12 +305,13 @@ struct _host_lookup_failed { static void test_client_host_lookup_failed_reply(const struct smtp_reply *reply, - struct _host_lookup_failed *ctx) + struct _host_lookup_failed *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); - test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); + test_assert(reply->status == + SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); if (--ctx->count == 0) { i_free(ctx); @@ -323,8 +320,7 @@ test_client_host_lookup_failed_reply(const struct smtp_reply *reply, } static bool -test_client_host_lookup_failed( - const struct smtp_client_settings *client_set) +test_client_host_lookup_failed(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -337,21 +333,21 @@ test_client_host_lookup_failed( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_host_lookup_failed_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_host_lookup_failed_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_host_lookup_failed_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_host_lookup_failed_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -368,8 +364,7 @@ static void test_host_lookup_failed(void) test_begin("host lookup failed"); test_run_client_server(&smtp_client_set, - test_client_host_lookup_failed, - NULL, 0, NULL); + test_client_host_lookup_failed, NULL, 0, NULL); test_end(); } @@ -379,8 +374,7 @@ static void test_host_lookup_failed(void) /* server */ -static void -test_server_connection_refused(unsigned int index ATTR_UNUSED) +static void test_server_connection_refused(unsigned int index ATTR_UNUSED) { i_close_fd(&fd_listen); } @@ -393,7 +387,7 @@ struct _connection_refused { static void test_client_connection_refused_reply(const struct smtp_reply *reply, - struct _connection_refused *ctx) + struct _connection_refused *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -407,8 +401,7 @@ test_client_connection_refused_reply(const struct smtp_reply *reply, } static bool -test_client_connection_refused( - const struct smtp_client_settings *client_set) +test_client_connection_refused(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -421,21 +414,23 @@ test_client_connection_refused( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_refused_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_refused_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_refused_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_refused_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -452,8 +447,8 @@ static void test_connection_refused(void) test_begin("connection refused"); test_run_client_server(&smtp_client_set, - test_client_connection_refused, - test_server_connection_refused, 1, NULL); + test_client_connection_refused, + test_server_connection_refused, 1, NULL); test_end(); } @@ -471,7 +466,7 @@ test_connection_lost_prematurely_input(struct server_connection *conn) line = i_stream_read_next_line(conn->conn.input); if (line == NULL) { if (conn->conn.input->eof || - conn->conn.input->stream_errno != 0) { + conn->conn.input->stream_errno != 0) { server_connection_deinit(&conn); } return; @@ -479,8 +474,7 @@ test_connection_lost_prematurely_input(struct server_connection *conn) server_connection_deinit(&conn); } -static int -test_connection_lost_prematurely_init(struct server_connection *conn) +static int test_connection_lost_prematurely_init(struct server_connection *conn) { o_stream_nsend_str(conn->conn.output, "220 testserver ESMTP Testfix (Frop/GNU)\r\n"); @@ -501,7 +495,8 @@ struct _connection_lost_prematurely { }; static void -test_client_connection_lost_prematurely_reply(const struct smtp_reply *reply, +test_client_connection_lost_prematurely_reply( + const struct smtp_reply *reply, struct _connection_lost_prematurely *ctx) { if (debug) @@ -528,21 +523,23 @@ test_client_connection_lost_prematurely( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_lost_prematurely_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_lost_prematurely_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_lost_prematurely_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_lost_prematurely_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -559,8 +556,9 @@ static void test_connection_lost_prematurely(void) test_begin("connection lost prematurely"); test_run_client_server(&smtp_client_set, - test_client_connection_lost_prematurely, - test_server_connection_lost_prematurely, 1, NULL); + test_client_connection_lost_prematurely, + test_server_connection_lost_prematurely, + 1, NULL); test_end(); } @@ -583,7 +581,7 @@ struct _connection_timed_out { static void test_client_connection_timed_out_reply(const struct smtp_reply *reply, - struct _connection_timed_out *ctx) + struct _connection_timed_out *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -597,8 +595,7 @@ test_client_connection_timed_out_reply(const struct smtp_reply *reply, } static bool -test_client_connection_timed_out( - const struct smtp_client_settings *client_set) +test_client_connection_timed_out(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -611,21 +608,23 @@ test_client_connection_timed_out( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_timed_out_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_timed_out_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_connection_timed_out_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_connection_timed_out_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -643,8 +642,8 @@ static void test_connection_timed_out(void) test_begin("connection timed out"); test_run_client_server(&smtp_client_set, - test_client_connection_timed_out, - test_server_connection_timed_out, 1, NULL); + test_client_connection_timed_out, + test_server_connection_timed_out, 1, NULL); test_end(); } @@ -656,7 +655,7 @@ static void test_connection_timed_out(void) static int test_broken_payload_input_line(struct server_connection *conn ATTR_UNUSED, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { return 0; } @@ -668,16 +667,16 @@ static void test_server_broken_payload(unsigned int index) } static int -test_broken_payload_chunking_input_line( - struct server_connection *conn, const char *line ATTR_UNUSED) +test_broken_payload_chunking_input_line(struct server_connection *conn, + const char *line ATTR_UNUSED) { if (conn->state == SERVER_CONNECTION_STATE_EHLO) { o_stream_nsend_str(conn->conn.output, - "250-testserver\r\n" - "250-PIPELINING\r\n" - "250-CHUNKING\r\n" - "250-ENHANCEDSTATUSCODES\r\n" - "250 DSN\r\n"); + "250-testserver\r\n" + "250-PIPELINING\r\n" + "250-CHUNKING\r\n" + "250-ENHANCEDSTATUSCODES\r\n" + "250 DSN\r\n"); return 1; } return 0; @@ -693,14 +692,14 @@ static void test_server_broken_payload_chunking(unsigned int index) static void test_client_broken_payload_rcpt_to_cb(const struct smtp_reply *reply, - void *context ATTR_UNUSED) + void *context ATTR_UNUSED) { test_assert(smtp_reply_is_success(reply)); } static void test_client_broken_payload_rcpt_data_cb(const struct smtp_reply *reply, - void *context ATTR_UNUSED) + void *context ATTR_UNUSED) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -710,7 +709,7 @@ test_client_broken_payload_rcpt_data_cb(const struct smtp_reply *reply, static void test_client_broken_payload_data_cb(const struct smtp_reply *reply, - void *context ATTR_UNUSED) + void *context ATTR_UNUSED) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -718,15 +717,13 @@ test_client_broken_payload_data_cb(const struct smtp_reply *reply, test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD); } -static void -test_client_broken_payload_finished(void *context ATTR_UNUSED) +static void test_client_broken_payload_finished(void *context ATTR_UNUSED) { io_loop_stop(ioloop); } static bool -test_client_broken_payload( - const struct smtp_client_settings *client_set) +test_client_broken_payload(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_transaction *strans; @@ -739,30 +736,32 @@ test_client_broken_payload( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); - strans = smtp_client_transaction_create(sconn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + strans = smtp_client_transaction_create( + sconn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_broken_payload_finished, NULL); smtp_client_connection_unref(&sconn); - smtp_client_transaction_add_rcpt(strans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + strans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_broken_payload_rcpt_to_cb, test_client_broken_payload_rcpt_data_cb, NULL); - smtp_client_transaction_send(strans, input, - test_client_broken_payload_data_cb, NULL); + smtp_client_transaction_send( + strans, input, test_client_broken_payload_data_cb, NULL); i_stream_unref(&input); return TRUE; } static bool -test_client_broken_payload_later( - const struct smtp_client_settings *client_set) +test_client_broken_payload_later(const struct smtp_client_settings *client_set) { static const char *message = "From: lucifer@example.com\r\n" @@ -800,22 +799,25 @@ test_client_broken_payload_later( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); - strans = smtp_client_transaction_create(sconn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + strans = smtp_client_transaction_create( + sconn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_broken_payload_finished, NULL); smtp_client_connection_unref(&sconn); - smtp_client_transaction_add_rcpt(strans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + strans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_broken_payload_rcpt_to_cb, test_client_broken_payload_rcpt_data_cb, NULL); - smtp_client_transaction_send - (strans, input, test_client_broken_payload_data_cb, NULL); + smtp_client_transaction_send( + strans, input, test_client_broken_payload_data_cb, NULL); i_stream_unref(&input); return TRUE; @@ -832,20 +834,20 @@ static void test_broken_payload(void) test_begin("broken payload"); test_run_client_server(&smtp_client_set, - test_client_broken_payload, - test_server_broken_payload, 1, NULL); + test_client_broken_payload, + test_server_broken_payload, 1, NULL); test_end(); test_begin("broken payload (later)"); test_run_client_server(&smtp_client_set, - test_client_broken_payload_later, - test_server_broken_payload, 1, NULL); + test_client_broken_payload_later, + test_server_broken_payload, 1, NULL); test_end(); test_begin("broken payload (later, chunking)"); test_run_client_server(&smtp_client_set, - test_client_broken_payload_later, - test_server_broken_payload_chunking, 1, NULL); + test_client_broken_payload_later, + test_server_broken_payload_chunking, 1, NULL); test_end(); } @@ -857,7 +859,7 @@ static void test_broken_payload(void) static int test_connection_lost_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { switch (conn->state) { case SERVER_CONNECTION_STATE_EHLO: @@ -900,7 +902,8 @@ test_connection_lost_input_line(struct server_connection *conn, static int test_connection_lost_input_data(struct server_connection *conn, - const unsigned char *data ATTR_UNUSED, size_t size ATTR_UNUSED) + const unsigned char *data ATTR_UNUSED, + size_t size ATTR_UNUSED) { sleep(1); server_connection_deinit(&conn); @@ -927,7 +930,7 @@ struct _connection_lost_peer { static void test_client_connection_lost_rcpt_to_cb(const struct smtp_reply *reply, - struct _connection_lost_peer *pctx) + struct _connection_lost_peer *pctx) { if (debug) { i_debug("RCPT TO REPLY[%u]: %s", @@ -937,15 +940,15 @@ test_client_connection_lost_rcpt_to_cb(const struct smtp_reply *reply, switch (pctx->index) { case 0: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); + SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); break; case 1: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); + SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); break; case 2: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); + SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); break; case 3: test_assert(smtp_reply_is_success(reply)); @@ -955,7 +958,7 @@ test_client_connection_lost_rcpt_to_cb(const struct smtp_reply *reply, static void test_client_connection_lost_rcpt_data_cb(const struct smtp_reply *reply, - struct _connection_lost_peer *pctx) + struct _connection_lost_peer *pctx) { if (debug) { i_debug("RCPT DATA REPLY[%u]: %s", @@ -973,14 +976,15 @@ test_client_connection_lost_rcpt_data_cb(const struct smtp_reply *reply, test_assert(FALSE); break; case 3: - test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); + test_assert(reply->status == + SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST); break; } } static void test_client_connection_lost_data_cb(const struct smtp_reply *reply, - struct _connection_lost_peer *pctx) + struct _connection_lost_peer *pctx) { if (debug) { i_debug("DATA REPLY[%u]: %s", @@ -1026,28 +1030,30 @@ test_client_connection_lost_submit(struct _connection_lost *ctx, input = i_stream_create_from_data(message, strlen(message)); i_stream_set_name(input, "message"); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); - strans = smtp_client_transaction_create(sconn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + strans = smtp_client_transaction_create( + sconn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_connection_lost_finished, pctx); smtp_client_connection_unref(&sconn); - smtp_client_transaction_add_rcpt(strans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + strans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_connection_lost_rcpt_to_cb, test_client_connection_lost_rcpt_data_cb, pctx); - smtp_client_transaction_send - (strans, input, test_client_connection_lost_data_cb, pctx); + smtp_client_transaction_send( + strans, input, test_client_connection_lost_data_cb, pctx); i_stream_unref(&input); } static bool -test_client_connection_lost( - const struct smtp_client_settings *client_set) +test_client_connection_lost(const struct smtp_client_settings *client_set) { struct _connection_lost *ctx; unsigned int i; @@ -1073,8 +1079,8 @@ static void test_connection_lost(void) test_begin("connection lost"); test_run_client_server(&smtp_client_set, - test_client_connection_lost, - test_server_connection_lost, 5, NULL); + test_client_connection_lost, + test_server_connection_lost, 5, NULL); test_end(); } @@ -1088,10 +1094,10 @@ static int test_unexpected_reply_init(struct server_connection *conn) { if (server_index == 5) { - o_stream_nsend_str(conn->conn.output, - "220 testserver ESMTP Testfix (Debian/GNU)\r\n"); - o_stream_nsend_str(conn->conn.output, - "421 testserver Server shutting down for maintenance\r\n"); + o_stream_nsend_str(conn->conn.output, "220 testserver " + "ESMTP Testfix (Debian/GNU)\r\n"); + o_stream_nsend_str(conn->conn.output, "421 testserver " + "Server shutting down for maintenance\r\n"); sleep(4); server_connection_deinit(&conn); return 1; @@ -1107,12 +1113,13 @@ test_unexpected_reply_input_line(struct server_connection *conn, case SERVER_CONNECTION_STATE_EHLO: if (server_index == 4) { o_stream_nsend_str(conn->conn.output, - "250-testserver\r\n" - "250-PIPELINING\r\n" - "250-ENHANCEDSTATUSCODES\r\n" - "250 DSN\r\n"); - o_stream_nsend_str(conn->conn.output, - "421 testserver Server shutting down for maintenance\r\n"); + "250-testserver\r\n" + "250-PIPELINING\r\n" + "250-ENHANCEDSTATUSCODES\r\n" + "250 DSN\r\n"); + o_stream_nsend_str( + conn->conn.output, "421 testserver " + "Server shutting down for maintenance\r\n"); sleep(4); server_connection_deinit(&conn); return -1; @@ -1121,9 +1128,10 @@ test_unexpected_reply_input_line(struct server_connection *conn, case SERVER_CONNECTION_STATE_MAIL_FROM: if (server_index == 3) { o_stream_nsend_str(conn->conn.output, - "250 2.1.0 Ok\r\n"); - o_stream_nsend_str(conn->conn.output, - "421 testserver Server shutting down for maintenance\r\n"); + "250 2.1.0 Ok\r\n"); + o_stream_nsend_str( + conn->conn.output, "421 testserver " + "Server shutting down for maintenance\r\n"); sleep(4); server_connection_deinit(&conn); return -1; @@ -1132,9 +1140,10 @@ test_unexpected_reply_input_line(struct server_connection *conn, case SERVER_CONNECTION_STATE_RCPT_TO: if (server_index == 2) { o_stream_nsend_str(conn->conn.output, - "250 2.1.5 Ok\r\n"); - o_stream_nsend_str(conn->conn.output, - "421 testserver Server shutting down for maintenance\r\n"); + "250 2.1.5 Ok\r\n"); + o_stream_nsend_str( + conn->conn.output, "421 testserver " + "Server shutting down for maintenance\r\n"); sleep(4); server_connection_deinit(&conn); return -1; @@ -1142,10 +1151,12 @@ test_unexpected_reply_input_line(struct server_connection *conn, break; case SERVER_CONNECTION_STATE_DATA: if (server_index == 1) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "354 End data with .\r\n"); - o_stream_nsend_str(conn->conn.output, - "421 testserver Server shutting down for maintenance\r\n"); + o_stream_nsend_str( + conn->conn.output, "421 testserver " + "Server shutting down for maintenance\r\n"); sleep(4); server_connection_deinit(&conn); return -1; @@ -1187,15 +1198,17 @@ struct _unexpected_reply_peer { static void test_client_unexpected_reply_login_cb(const struct smtp_reply *reply, - void *context) + void *context) { struct _unexpected_reply_peer *pctx = (struct _unexpected_reply_peer *)context; pctx->login_callback = TRUE; - if (debug) - i_debug("LOGIN REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("LOGIN REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } switch (pctx->index) { case 0: case 1: case 2: case 3: case 4: @@ -1209,10 +1222,12 @@ test_client_unexpected_reply_login_cb(const struct smtp_reply *reply, static void test_client_unexpected_reply_mail_from_cb(const struct smtp_reply *reply, - struct _unexpected_reply_peer *pctx) + struct _unexpected_reply_peer *pctx) { - if (debug) - i_debug("MAIL FROM REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("MAIL FROM REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->mail_from_callback = TRUE; @@ -1228,10 +1243,12 @@ test_client_unexpected_reply_mail_from_cb(const struct smtp_reply *reply, static void test_client_unexpected_reply_rcpt_to_cb(const struct smtp_reply *reply, - struct _unexpected_reply_peer *pctx) + struct _unexpected_reply_peer *pctx) { - if (debug) - i_debug("RCPT TO REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("RCPT TO REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->rcpt_to_callback = TRUE; @@ -1247,10 +1264,12 @@ test_client_unexpected_reply_rcpt_to_cb(const struct smtp_reply *reply, static void test_client_unexpected_reply_rcpt_data_cb(const struct smtp_reply *reply, - struct _unexpected_reply_peer *pctx) + struct _unexpected_reply_peer *pctx) { - if (debug) - i_debug("RCPT DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("RCPT DATA REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->rcpt_data_callback = TRUE; @@ -1268,10 +1287,12 @@ test_client_unexpected_reply_rcpt_data_cb(const struct smtp_reply *reply, static void test_client_unexpected_reply_data_cb(const struct smtp_reply *reply, - struct _unexpected_reply_peer *pctx) + struct _unexpected_reply_peer *pctx) { - if (debug) - i_debug("DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("DATA REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->data_callback = TRUE; @@ -1334,8 +1355,8 @@ test_client_unexpected_reply_submit2(struct _unexpected_reply_peer *pctx) input = i_stream_create_from_data(message, strlen(message)); i_stream_set_name(input, "message"); - smtp_client_transaction_send - (strans, input, test_client_unexpected_reply_data_cb, pctx); + smtp_client_transaction_send( + strans, input, test_client_unexpected_reply_data_cb, pctx); i_stream_unref(&input); } @@ -1344,19 +1365,20 @@ test_client_unexpected_reply_submit1(struct _unexpected_reply_peer *pctx) { timeout_remove(&pctx->to); - smtp_client_transaction_add_rcpt(pctx->trans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + pctx->trans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_unexpected_reply_rcpt_to_cb, test_client_unexpected_reply_rcpt_data_cb, pctx); - pctx->to = timeout_add_short(500, - test_client_unexpected_reply_submit2, pctx); + pctx->to = timeout_add_short( + 500, test_client_unexpected_reply_submit2, pctx); } static void test_client_unexpected_reply_submit(struct _unexpected_reply *ctx, - unsigned int index) + unsigned int index) { struct _unexpected_reply_peer *pctx; @@ -1364,26 +1386,28 @@ test_client_unexpected_reply_submit(struct _unexpected_reply *ctx, pctx->context = ctx; pctx->index = index; - pctx->conn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + pctx->conn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); - pctx->trans = smtp_client_transaction_create(pctx->conn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + pctx->trans = smtp_client_transaction_create( + pctx->conn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_unexpected_reply_finished, pctx); - smtp_client_connection_connect(pctx->conn, - test_client_unexpected_reply_login_cb, (void *)pctx); - smtp_client_transaction_start(pctx->trans, - test_client_unexpected_reply_mail_from_cb, pctx); + smtp_client_connection_connect( + pctx->conn, test_client_unexpected_reply_login_cb, + (void *)pctx); + smtp_client_transaction_start( + pctx->trans, test_client_unexpected_reply_mail_from_cb, pctx); smtp_client_connection_unref(&pctx->conn); - pctx->to = timeout_add_short(500, - test_client_unexpected_reply_submit1, pctx); + pctx->to = timeout_add_short( + 500, test_client_unexpected_reply_submit1, pctx); } static bool -test_client_unexpected_reply( - const struct smtp_client_settings *client_set) +test_client_unexpected_reply(const struct smtp_client_settings *client_set) { struct _unexpected_reply *ctx; unsigned int i; @@ -1409,8 +1433,8 @@ static void test_unexpected_reply(void) test_begin("unexpected reply"); test_run_client_server(&smtp_client_set, - test_client_unexpected_reply, - test_server_unexpected_reply, 6, NULL); + test_client_unexpected_reply, + test_server_unexpected_reply, 6, NULL); test_end(); } @@ -1422,7 +1446,7 @@ static void test_unexpected_reply(void) static int test_partial_reply_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { if (conn->state == SERVER_CONNECTION_STATE_EHLO) return 0; @@ -1446,7 +1470,7 @@ struct _partial_reply { static void test_client_partial_reply_reply(const struct smtp_reply *reply, - struct _partial_reply *ctx) + struct _partial_reply *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -1460,8 +1484,7 @@ test_client_partial_reply_reply(const struct smtp_reply *reply, } static bool -test_client_partial_reply( - const struct smtp_client_settings *client_set) +test_client_partial_reply(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -1472,21 +1495,23 @@ test_client_partial_reply( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_partial_reply_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_partial_reply_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_partial_reply_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_partial_reply_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -1503,8 +1528,8 @@ static void test_partial_reply(void) test_begin("partial reply"); test_run_client_server(&smtp_client_set, - test_client_partial_reply, - test_server_partial_reply, 1, NULL); + test_client_partial_reply, + test_server_partial_reply, 1, NULL); test_end(); } @@ -1518,7 +1543,8 @@ static int test_premature_reply_init(struct server_connection *conn) { if (server_index == 5) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "220 testserver ESMTP Testfix (Debian/GNU)\r\n" "250-testserver\r\n" "250-PIPELINING\r\n" @@ -1542,11 +1568,11 @@ test_premature_reply_input_line(struct server_connection *conn, const char *line i_debug("[%u] EHLO", server_index); if (server_index == 4) { o_stream_nsend_str(conn->conn.output, - "250-testserver\r\n" - "250-PIPELINING\r\n" - "250-ENHANCEDSTATUSCODES\r\n" - "250 DSN\r\n" - "250 2.1.0 Ok\r\n"); + "250-testserver\r\n" + "250-PIPELINING\r\n" + "250-ENHANCEDSTATUSCODES\r\n" + "250 DSN\r\n" + "250 2.1.0 Ok\r\n"); conn->state = SERVER_CONNECTION_STATE_MAIL_FROM; return 1; } @@ -1558,8 +1584,8 @@ test_premature_reply_input_line(struct server_connection *conn, const char *line } if (server_index == 3) { o_stream_nsend_str(conn->conn.output, - "250 2.1.0 Ok\r\n" - "250 2.1.5 Ok\r\n"); + "250 2.1.0 Ok\r\n" + "250 2.1.5 Ok\r\n"); sleep(4); server_connection_deinit(&conn); return -1; @@ -1567,7 +1593,8 @@ test_premature_reply_input_line(struct server_connection *conn, const char *line break; case SERVER_CONNECTION_STATE_RCPT_TO: if (server_index == 2) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "250 2.1.5 Ok\r\n" "354 End data with .\r\n"); sleep(4); @@ -1577,7 +1604,8 @@ test_premature_reply_input_line(struct server_connection *conn, const char *line break; case SERVER_CONNECTION_STATE_DATA: if (server_index == 1) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "354 End data with .\r\n" "250 2.0.0 Ok: queued as 35424ed4af24\r\n"); sleep(4); @@ -1621,7 +1649,7 @@ struct _premature_reply_peer { static void test_client_premature_reply_login_cb(const struct smtp_reply *reply, - void *context) + void *context) { struct _premature_reply_peer *pctx = (struct _premature_reply_peer *)context; @@ -1649,7 +1677,7 @@ test_client_premature_reply_login_cb(const struct smtp_reply *reply, static void test_client_premature_reply_mail_from_cb(const struct smtp_reply *reply, - struct _premature_reply_peer *pctx) + struct _premature_reply_peer *pctx) { if (debug) { i_debug("MAIL FROM REPLY[%u]: %s", @@ -1671,7 +1699,7 @@ test_client_premature_reply_mail_from_cb(const struct smtp_reply *reply, static void test_client_premature_reply_rcpt_to_cb(const struct smtp_reply *reply, - struct _premature_reply_peer *pctx) + struct _premature_reply_peer *pctx) { if (debug) { i_debug("RCPT TO REPLY[%u]: %s", @@ -1693,7 +1721,7 @@ test_client_premature_reply_rcpt_to_cb(const struct smtp_reply *reply, static void test_client_premature_reply_rcpt_data_cb(const struct smtp_reply *reply, - struct _premature_reply_peer *pctx) + struct _premature_reply_peer *pctx) { if (debug) { i_debug("RCPT DATA REPLY[%u]: %s", @@ -1717,7 +1745,7 @@ test_client_premature_reply_rcpt_data_cb(const struct smtp_reply *reply, static void test_client_premature_reply_data_cb(const struct smtp_reply *reply, - struct _premature_reply_peer *pctx) + struct _premature_reply_peer *pctx) { if (debug) { i_debug("DATA REPLY[%u]: %s", @@ -1794,8 +1822,8 @@ test_client_premature_reply_submit3(struct _premature_reply_peer *pctx) input = i_stream_create_from_data(message, strlen(message)); i_stream_set_name(input, "message"); - smtp_client_transaction_send - (strans, input, test_client_premature_reply_data_cb, pctx); + smtp_client_transaction_send( + strans, input, test_client_premature_reply_data_cb, pctx); i_stream_unref(&input); } @@ -1807,17 +1835,17 @@ test_client_premature_reply_submit2(struct _premature_reply_peer *pctx) if (debug) i_debug("SUBMIT2[%u]", pctx->index); - smtp_client_transaction_add_rcpt(pctx->trans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + pctx->trans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_premature_reply_rcpt_to_cb, test_client_premature_reply_rcpt_data_cb, pctx); - pctx->to = timeout_add_short(500, - test_client_premature_reply_submit3, pctx); + pctx->to = timeout_add_short( + 500, test_client_premature_reply_submit3, pctx); } - static void test_client_premature_reply_submit1(struct _premature_reply_peer *pctx) { @@ -1826,16 +1854,16 @@ test_client_premature_reply_submit1(struct _premature_reply_peer *pctx) if (debug) i_debug("SUBMIT1[%u]", pctx->index); - smtp_client_transaction_start(pctx->trans, - test_client_premature_reply_mail_from_cb, pctx); + smtp_client_transaction_start( + pctx->trans, test_client_premature_reply_mail_from_cb, pctx); - pctx->to = timeout_add_short(500, - test_client_premature_reply_submit2, pctx); + pctx->to = timeout_add_short( + 500, test_client_premature_reply_submit2, pctx); } static void test_client_premature_reply_submit(struct _premature_reply *ctx, - unsigned int index) + unsigned int index) { struct _premature_reply_peer *pctx; struct smtp_client_connection *conn; @@ -1844,24 +1872,25 @@ test_client_premature_reply_submit(struct _premature_reply *ctx, pctx->context = ctx; pctx->index = index; - pctx->conn = conn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + pctx->conn = conn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); - pctx->trans = smtp_client_transaction_create(conn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + pctx->trans = smtp_client_transaction_create( + conn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_premature_reply_finished, pctx); - smtp_client_connection_connect(conn, - test_client_premature_reply_login_cb, (void *)pctx); + smtp_client_connection_connect( + conn, test_client_premature_reply_login_cb, (void *)pctx); smtp_client_connection_unref(&conn); - pctx->to = timeout_add_short(500, - test_client_premature_reply_submit1, pctx); + pctx->to = timeout_add_short( + 500, test_client_premature_reply_submit1, pctx); } static bool -test_client_premature_reply( - const struct smtp_client_settings *client_set) +test_client_premature_reply(const struct smtp_client_settings *client_set) { struct _premature_reply *ctx; unsigned int i; @@ -1887,8 +1916,8 @@ static void test_premature_reply(void) test_begin("premature reply"); test_run_client_server(&smtp_client_set, - test_client_premature_reply, - test_server_premature_reply, 6, NULL); + test_client_premature_reply, + test_server_premature_reply, 6, NULL); test_end(); } @@ -1916,7 +1945,7 @@ test_early_data_reply_input_line(struct server_connection *conn ATTR_UNUSED, if (debug) i_debug("[%u] REPLIED 354", server_index); o_stream_nsend_str(conn->conn.output, - "354 End data with .\r\n"); + "354 End data with .\r\n"); conn->context = (void*)1; return 1; } @@ -1926,7 +1955,7 @@ test_early_data_reply_input_line(struct server_connection *conn ATTR_UNUSED, i_debug("[%u] FINISHED TRANSACTION", server_index); o_stream_nsend_str(conn->conn.output, - "250 2.0.0 Ok: queued as 73BDE342129\r\n"); + "250 2.0.0 Ok: queued as 73BDE342129\r\n"); return 1; } @@ -1936,10 +1965,12 @@ test_early_data_reply_input_line(struct server_connection *conn ATTR_UNUSED, server_index); if (server_index == 0) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "250 2.0.0 Ok: queued as 73BDE342129\r\n"); } else { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "452 4.3.1 Mail system full\r\n"); } } @@ -2012,8 +2043,8 @@ test_client_early_data_reply_rcpt_to_cb(const struct smtp_reply *reply, test_assert(smtp_reply_is_success(reply)); - pctx->to = timeout_add_short(1000, - test_client_early_data_reply_submit1, pctx); + pctx->to = timeout_add_short( + 1000, test_client_early_data_reply_submit1, pctx); } static void @@ -2127,19 +2158,22 @@ test_client_early_data_reply_submit(struct _early_data_reply *ctx, input = i_stream_create_fd_autoclose(&pipefd[0], 1024); pctx->output = o_stream_create_fd_autoclose(&pipefd[1], 1024); - pctx->conn = conn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + pctx->conn = conn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(conn, test_client_early_data_reply_login_cb, (void *)pctx); - pctx->trans = smtp_client_transaction_create(conn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + pctx->trans = smtp_client_transaction_create( + conn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_early_data_reply_finished, pctx); - smtp_client_transaction_add_rcpt(pctx->trans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + pctx->trans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_early_data_reply_rcpt_to_cb, test_client_early_data_reply_rcpt_data_cb, pctx); smtp_client_transaction_start(pctx->trans, @@ -2155,8 +2189,7 @@ test_client_early_data_reply_submit(struct _early_data_reply *ctx, } static bool -test_client_early_data_reply( - const struct smtp_client_settings *client_set) +test_client_early_data_reply(const struct smtp_client_settings *client_set) { struct _early_data_reply *ctx; unsigned int i; @@ -2182,8 +2215,8 @@ static void test_early_data_reply(void) test_begin("early data reply"); test_run_client_server(&smtp_client_set, - test_client_early_data_reply, - test_server_early_data_reply, 3, NULL); + test_client_early_data_reply, + test_server_early_data_reply, 3, NULL); test_end(); } @@ -2200,7 +2233,7 @@ test_bad_reply_input_line(struct server_connection *conn, if (conn->state == SERVER_CONNECTION_STATE_EHLO) return 0; o_stream_nsend_str(conn->conn.output, - "666 Really bad reply\r\n"); + "666 Really bad reply\r\n"); server_connection_deinit(&conn); return -1; } @@ -2245,21 +2278,23 @@ test_client_bad_reply( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_bad_reply_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_bad_reply_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_bad_reply_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_bad_reply_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -2276,8 +2311,8 @@ static void test_bad_reply(void) test_begin("bad reply"); test_run_client_server(&smtp_client_set, - test_client_bad_reply, - test_server_bad_reply, 1, NULL); + test_client_bad_reply, + test_server_bad_reply, 1, NULL); test_end(); } @@ -2287,8 +2322,7 @@ static void test_bad_reply(void) /* server */ -static int -test_bad_greeting_init(struct server_connection *conn) +static int test_bad_greeting_init(struct server_connection *conn) { switch (server_index) { case 0: @@ -2327,7 +2361,7 @@ struct _bad_greeting_peer { static void test_client_bad_greeting_reply(const struct smtp_reply *reply, - struct _bad_greeting_peer *pctx) + struct _bad_greeting_peer *pctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -2354,8 +2388,7 @@ test_client_bad_greeting_reply(const struct smtp_reply *reply, } static void -test_client_bad_greeting_submit(struct _bad_greeting *ctx, - unsigned int index) +test_client_bad_greeting_submit(struct _bad_greeting *ctx, unsigned int index) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -2365,19 +2398,19 @@ test_client_bad_greeting_submit(struct _bad_greeting *ctx, pctx->context = ctx; pctx->index = index; - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_bad_greeting_reply, pctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_bad_greeting_reply, pctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); } static bool -test_client_bad_greeting( - const struct smtp_client_settings *client_set) +test_client_bad_greeting(const struct smtp_client_settings *client_set) { struct _bad_greeting *ctx; @@ -2402,8 +2435,8 @@ static void test_bad_greeting(void) test_begin("bad greeting"); test_run_client_server(&smtp_client_set, - test_client_bad_greeting, - test_server_bad_greeting, 3, NULL); + test_client_bad_greeting, + test_server_bad_greeting, 3, NULL); test_end(); } @@ -2415,7 +2448,7 @@ static void test_bad_greeting(void) static int test_command_timed_out_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { if (conn->state == SERVER_CONNECTION_STATE_EHLO) return 0; @@ -2438,7 +2471,7 @@ struct _command_timed_out { static void test_client_command_timed_out_reply(const struct smtp_reply *reply, - struct _command_timed_out *ctx) + struct _command_timed_out *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); @@ -2452,8 +2485,7 @@ test_client_command_timed_out_reply(const struct smtp_reply *reply, } static bool -test_client_command_timed_out( - const struct smtp_client_settings *client_set) +test_client_command_timed_out(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -2466,12 +2498,13 @@ test_client_command_timed_out( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_command_timed_out_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_command_timed_out_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -2489,8 +2522,8 @@ static void test_command_timed_out(void) test_begin("command timed out"); test_run_client_server(&smtp_client_set, - test_client_command_timed_out, - test_server_command_timed_out, 1, NULL); + test_client_command_timed_out, + test_server_command_timed_out, 1, NULL); test_end(); } @@ -2502,7 +2535,7 @@ static void test_command_timed_out(void) static int test_command_aborted_early_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { if (conn->state == SERVER_CONNECTION_STATE_EHLO) return 0; @@ -2527,7 +2560,8 @@ struct _command_aborted_early { }; static void -test_client_command_aborted_early_reply(const struct smtp_reply *reply, +test_client_command_aborted_early_reply( + const struct smtp_reply *reply, struct _command_aborted_early *ctx ATTR_UNUSED) { if (debug) @@ -2538,8 +2572,7 @@ test_client_command_aborted_early_reply(const struct smtp_reply *reply, } static void -test_client_command_aborted_early_timeout( - struct _command_aborted_early *ctx) +test_client_command_aborted_early_timeout(struct _command_aborted_early *ctx) { timeout_remove(&ctx->to); @@ -2552,8 +2585,8 @@ test_client_command_aborted_early_timeout( /* wait a little for server to actually respond to an already aborted request */ - ctx->to = timeout_add_short(1000, - test_client_command_aborted_early_timeout, ctx); + ctx->to = timeout_add_short( + 1000, test_client_command_aborted_early_timeout, ctx); } else { if (debug) i_debug("FINISHED"); @@ -2565,8 +2598,7 @@ test_client_command_aborted_early_timeout( } static bool -test_client_command_aborted_early( - const struct smtp_client_settings *client_set) +test_client_command_aborted_early(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct _command_aborted_early *ctx; @@ -2600,8 +2632,8 @@ static void test_command_aborted_early(void) test_begin("command aborted early"); test_run_client_server(&smtp_client_set, - test_client_command_aborted_early, - test_server_command_aborted_early, 1, NULL); + test_client_command_aborted_early, + test_server_command_aborted_early, 1, NULL); test_end(); } @@ -2613,7 +2645,7 @@ static void test_command_aborted_early(void) static int test_client_deinit_early_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { if (conn->state == SERVER_CONNECTION_STATE_EHLO) return 0; @@ -2638,7 +2670,8 @@ struct _client_deinit_early { }; static void -test_client_client_deinit_early_reply(const struct smtp_reply *reply, +test_client_client_deinit_early_reply( + const struct smtp_reply *reply, struct _client_deinit_early *ctx ATTR_UNUSED) { if (debug) @@ -2649,8 +2682,7 @@ test_client_client_deinit_early_reply(const struct smtp_reply *reply, } static void -test_client_client_deinit_early_timeout( - struct _client_deinit_early *ctx) +test_client_client_deinit_early_timeout(struct _client_deinit_early *ctx) { timeout_remove(&ctx->to); @@ -2663,8 +2695,7 @@ test_client_client_deinit_early_timeout( } static bool -test_client_client_deinit_early( - const struct smtp_client_settings *client_set) +test_client_client_deinit_early(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct _client_deinit_early *ctx; @@ -2673,17 +2704,18 @@ test_client_client_deinit_early( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[0], + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[0], SMTP_CLIENT_SSL_MODE_NONE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - ctx->cmd = smtp_client_command_new(sconn, 0, - test_client_client_deinit_early_reply, ctx); + ctx->cmd = smtp_client_command_new( + sconn, 0, test_client_client_deinit_early_reply, ctx); smtp_client_command_write(ctx->cmd, "FROP"); smtp_client_command_submit(ctx->cmd); - ctx->to = timeout_add_short(500, - test_client_client_deinit_early_timeout, ctx); + ctx->to = timeout_add_short( + 500, test_client_client_deinit_early_timeout, ctx); return TRUE; } @@ -2699,8 +2731,8 @@ static void test_client_deinit_early(void) test_begin("client deinit early"); test_run_client_server(&smtp_client_set, - test_client_client_deinit_early, - test_server_client_deinit_early, 1, NULL); + test_client_client_deinit_early, + test_server_client_deinit_early, 1, NULL); test_end(); } @@ -2716,12 +2748,13 @@ struct _dns_service_failure { static void test_client_dns_service_failure_reply(const struct smtp_reply *reply, - struct _dns_service_failure *ctx) + struct _dns_service_failure *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); - test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); + test_assert(reply->status == + SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); if (--ctx->count == 0) { i_free(ctx); @@ -2730,8 +2763,7 @@ test_client_dns_service_failure_reply(const struct smtp_reply *reply, } static bool -test_client_dns_service_failure( - const struct smtp_client_settings *client_set) +test_client_dns_service_failure(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -2744,21 +2776,21 @@ test_client_dns_service_failure( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_service_failure_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_service_failure_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "host.in-addr.arpa", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_service_failure_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_service_failure_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -2776,8 +2808,7 @@ static void test_dns_service_failure(void) test_begin("dns service failure"); test_run_client_server(&smtp_client_set, - test_client_dns_service_failure, - NULL, 0, NULL); + test_client_dns_service_failure, NULL, 0, NULL); test_end(); } @@ -2787,8 +2818,7 @@ static void test_dns_service_failure(void) /* dns */ -static void -test_dns_timeout_input(struct server_connection *conn ATTR_UNUSED) +static void test_dns_timeout_input(struct server_connection *conn ATTR_UNUSED) { /* hang */ sleep(100); @@ -2809,12 +2839,13 @@ struct _dns_timeout { static void test_client_dns_timeout_reply(const struct smtp_reply *reply, - struct _dns_timeout *ctx) + struct _dns_timeout *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); - test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); + test_assert(reply->status == + SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); if (--ctx->count == 0) { i_free(ctx); @@ -2823,8 +2854,7 @@ test_client_dns_timeout_reply(const struct smtp_reply *reply, } static bool -test_client_dns_timeout( - const struct smtp_client_settings *client_set) +test_client_dns_timeout(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -2837,21 +2867,21 @@ test_client_dns_timeout( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "example.com", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "example.com", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_timeout_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_timeout_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "example.com", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "example.com", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_timeout_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_timeout_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -2870,8 +2900,8 @@ static void test_dns_timeout(void) test_begin("dns timeout"); test_run_client_server(&smtp_client_set, - test_client_dns_timeout, NULL, 0, - test_dns_dns_timeout); + test_client_dns_timeout, NULL, 0, + test_dns_dns_timeout); test_end(); } @@ -2884,7 +2914,8 @@ static void test_dns_timeout(void) static void test_dns_lookup_failure_input(struct server_connection *conn) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, t_strdup_printf("VERSION\tdns\t1\t0\n%d\tFAIL\n", EAI_FAIL)); server_connection_deinit(&conn); } @@ -2903,12 +2934,13 @@ struct _dns_lookup_failure { static void test_client_dns_lookup_failure_reply(const struct smtp_reply *reply, - struct _dns_lookup_failure *ctx) + struct _dns_lookup_failure *ctx) { if (debug) i_debug("REPLY: %s", smtp_reply_log(reply)); - test_assert(reply->status == SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); + test_assert(reply->status == + SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED); if (--ctx->count == 0) { i_free(ctx); @@ -2917,8 +2949,7 @@ test_client_dns_lookup_failure_reply(const struct smtp_reply *reply, } static bool -test_client_dns_lookup_failure( - const struct smtp_client_settings *client_set) +test_client_dns_lookup_failure(const struct smtp_client_settings *client_set) { struct smtp_client_connection *sconn; struct smtp_client_command *scmd; @@ -2931,21 +2962,21 @@ test_client_dns_lookup_failure( smtp_client = smtp_client_init(client_set); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "example.com", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "example.com", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_lookup_failure_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_lookup_failure_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); - sconn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, "example.com", 465, + sconn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, "example.com", 465, SMTP_CLIENT_SSL_MODE_IMMEDIATE, NULL); smtp_client_connection_connect(sconn, NULL, NULL); - scmd = smtp_client_command_new(sconn, 0, - test_client_dns_lookup_failure_reply, ctx); + scmd = smtp_client_command_new( + sconn, 0, test_client_dns_lookup_failure_reply, ctx); smtp_client_command_write(scmd, "FROP"); smtp_client_command_submit(scmd); @@ -2963,8 +2994,8 @@ static void test_dns_lookup_failure(void) test_begin("dns lookup failure"); test_run_client_server(&smtp_client_set, - test_client_dns_lookup_failure, NULL, 0, - test_dns_dns_lookup_failure); + test_client_dns_lookup_failure, NULL, 0, + test_dns_dns_lookup_failure); test_end(); } @@ -2976,12 +3007,13 @@ static void test_dns_lookup_failure(void) static int test_authentication_failed_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { switch (conn->state) { case SERVER_CONNECTION_STATE_EHLO: if (server_index == 1) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "250-testserver\r\n" "250-PIPELINING\r\n" "250-ENHANCEDSTATUSCODES\r\n" @@ -2993,7 +3025,8 @@ test_authentication_failed_input_line(struct server_connection *conn, break; case SERVER_CONNECTION_STATE_MAIL_FROM: if (server_index == 1) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "535 5.7.8 " "Authentication credentials invalid\r\n"); sleep(10); @@ -3029,7 +3062,7 @@ struct _authentication_failed_peer { static void test_client_authentication_failed_login_cb(const struct smtp_reply *reply, - void *context) + void *context) { struct _authentication_failed_peer *pctx = (struct _authentication_failed_peer *)context; @@ -3042,7 +3075,7 @@ test_client_authentication_failed_login_cb(const struct smtp_reply *reply, switch (pctx->index) { case 0: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); + SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); break; case 1: test_assert(reply->status == 535); @@ -3051,7 +3084,8 @@ test_client_authentication_failed_login_cb(const struct smtp_reply *reply, } static void -test_client_authentication_failed_mail_from_cb(const struct smtp_reply *reply, +test_client_authentication_failed_mail_from_cb( + const struct smtp_reply *reply, struct _authentication_failed_peer *pctx) { if (debug) { @@ -3062,7 +3096,7 @@ test_client_authentication_failed_mail_from_cb(const struct smtp_reply *reply, switch (pctx->index) { case 0: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); + SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); break; case 1: test_assert(reply->status == 535); @@ -3071,7 +3105,8 @@ test_client_authentication_failed_mail_from_cb(const struct smtp_reply *reply, } static void -test_client_authentication_failed_rcpt_to_cb(const struct smtp_reply *reply, +test_client_authentication_failed_rcpt_to_cb( + const struct smtp_reply *reply, struct _authentication_failed_peer *pctx) { if (debug) { @@ -3082,7 +3117,7 @@ test_client_authentication_failed_rcpt_to_cb(const struct smtp_reply *reply, switch (pctx->index) { case 0: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); + SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); break; case 1: test_assert(reply->status == 535); @@ -3091,7 +3126,8 @@ test_client_authentication_failed_rcpt_to_cb(const struct smtp_reply *reply, } static void -test_client_authentication_failed_rcpt_data_cb(const struct smtp_reply *reply, +test_client_authentication_failed_rcpt_data_cb( + const struct smtp_reply *reply, struct _authentication_failed_peer *pctx) { if (debug) { @@ -3103,7 +3139,8 @@ test_client_authentication_failed_rcpt_data_cb(const struct smtp_reply *reply, } static void -test_client_authentication_failed_data_cb(const struct smtp_reply *reply, +test_client_authentication_failed_data_cb( + const struct smtp_reply *reply, struct _authentication_failed_peer *pctx) { if (debug) { @@ -3114,7 +3151,7 @@ test_client_authentication_failed_data_cb(const struct smtp_reply *reply, switch (pctx->index) { case 0: test_assert(reply->status == - SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); + SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED); break; case 1: test_assert(reply->status == 535); @@ -3123,7 +3160,8 @@ test_client_authentication_failed_data_cb(const struct smtp_reply *reply, } static void -test_client_authentication_failed_finished(struct _authentication_failed_peer *pctx) +test_client_authentication_failed_finished( + struct _authentication_failed_peer *pctx) { struct _authentication_failed *ctx = pctx->context; @@ -3140,7 +3178,7 @@ test_client_authentication_failed_finished(struct _authentication_failed_peer *p static void test_client_authentication_failed_submit(struct _authentication_failed *ctx, - unsigned int index) + unsigned int index) { struct _authentication_failed_peer *pctx; struct smtp_client_settings smtp_set; @@ -3160,36 +3198,41 @@ test_client_authentication_failed_submit(struct _authentication_failed *ctx, smtp_set.username = "peter.wolfsen"; smtp_set.password = "crybaby"; - pctx->conn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + pctx->conn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, &smtp_set); - pctx->trans = smtp_client_transaction_create(pctx->conn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + pctx->trans = smtp_client_transaction_create( + pctx->conn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_authentication_failed_finished, pctx); - smtp_client_connection_connect(pctx->conn, - test_client_authentication_failed_login_cb, (void *)pctx); - smtp_client_transaction_start(pctx->trans, - test_client_authentication_failed_mail_from_cb, pctx); + smtp_client_connection_connect( + pctx->conn, test_client_authentication_failed_login_cb, + (void *)pctx); + smtp_client_transaction_start( + pctx->trans, test_client_authentication_failed_mail_from_cb, + pctx); smtp_client_connection_unref(&pctx->conn); - smtp_client_transaction_add_rcpt(pctx->trans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + pctx->trans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_authentication_failed_rcpt_to_cb, test_client_authentication_failed_rcpt_data_cb, pctx); input = i_stream_create_from_data(message, strlen(message)); i_stream_set_name(input, "message"); - smtp_client_transaction_send(pctx->trans, - input, test_client_authentication_failed_data_cb, pctx); + smtp_client_transaction_send( + pctx->trans, input, + test_client_authentication_failed_data_cb, pctx); i_stream_unref(&input); } static bool -test_client_authentication_failed( - const struct smtp_client_settings *client_set) +test_client_authentication_failed(const struct smtp_client_settings *client_set) { struct _authentication_failed *ctx; unsigned int i; @@ -3216,8 +3259,8 @@ static void test_authentication_failed(void) test_begin("authentication failed"); test_expect_errors(1); test_run_client_server(&smtp_client_set, - test_client_authentication_failed, - test_server_authentication_failed, 2, NULL); + test_client_authentication_failed, + test_server_authentication_failed, 2, NULL); test_end(); } @@ -3229,7 +3272,7 @@ static void test_authentication_failed(void) static int test_transaction_timeout_input_line(struct server_connection *conn, - const char *line ATTR_UNUSED) + const char *line ATTR_UNUSED) { switch (conn->state) { case SERVER_CONNECTION_STATE_EHLO: @@ -3280,11 +3323,14 @@ struct _transaction_timeout_peer { }; static void -test_client_transaction_timeout_mail_from_cb(const struct smtp_reply *reply, +test_client_transaction_timeout_mail_from_cb( + const struct smtp_reply *reply, struct _transaction_timeout_peer *pctx) { - if (debug) - i_debug("MAIL FROM REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("MAIL FROM REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->mail_from_callback = TRUE; @@ -3299,11 +3345,13 @@ test_client_transaction_timeout_mail_from_cb(const struct smtp_reply *reply, } static void -test_client_transaction_timeout_rcpt_to_cb(const struct smtp_reply *reply, - struct _transaction_timeout_peer *pctx) +test_client_transaction_timeout_rcpt_to_cb( + const struct smtp_reply *reply, struct _transaction_timeout_peer *pctx) { - if (debug) - i_debug("RCPT TO REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("RCPT TO REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->rcpt_to_callback = TRUE; @@ -3318,11 +3366,13 @@ test_client_transaction_timeout_rcpt_to_cb(const struct smtp_reply *reply, } static void -test_client_transaction_timeout_rcpt_data_cb(const struct smtp_reply *reply, - struct _transaction_timeout_peer *pctx) +test_client_transaction_timeout_rcpt_data_cb( + const struct smtp_reply *reply, struct _transaction_timeout_peer *pctx) { - if (debug) - i_debug("RCPT DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("RCPT DATA REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->rcpt_data_callback = TRUE; @@ -3340,10 +3390,12 @@ test_client_transaction_timeout_rcpt_data_cb(const struct smtp_reply *reply, static void test_client_transaction_timeout_data_cb(const struct smtp_reply *reply, - struct _transaction_timeout_peer *pctx) + struct _transaction_timeout_peer *pctx) { - if (debug) - i_debug("DATA REPLY[%u]: %s", pctx->index, smtp_reply_log(reply)); + if (debug) { + i_debug("DATA REPLY[%u]: %s", + pctx->index, smtp_reply_log(reply)); + } pctx->data_callback = TRUE; @@ -3406,8 +3458,8 @@ test_client_transaction_timeout_submit2(struct _transaction_timeout_peer *pctx) input = i_stream_create_from_data(message, strlen(message)); i_stream_set_name(input, "message"); - smtp_client_transaction_send - (strans, input, test_client_transaction_timeout_data_cb, pctx); + smtp_client_transaction_send( + strans, input, test_client_transaction_timeout_data_cb, pctx); i_stream_unref(&input); } @@ -3416,19 +3468,20 @@ test_client_transaction_timeout_submit1(struct _transaction_timeout_peer *pctx) { timeout_remove(&pctx->to); - smtp_client_transaction_add_rcpt(pctx->trans, - &((struct smtp_address){.localpart = "rcpt", - .domain = "example.com"}), NULL, + smtp_client_transaction_add_rcpt( + pctx->trans, &((struct smtp_address){ + .localpart = "rcpt", + .domain = "example.com"}), NULL, test_client_transaction_timeout_rcpt_to_cb, test_client_transaction_timeout_rcpt_data_cb, pctx); - pctx->to = timeout_add_short(500, - test_client_transaction_timeout_submit2, pctx); + pctx->to = timeout_add_short( + 500, test_client_transaction_timeout_submit2, pctx); } static void test_client_transaction_timeout_submit(struct _transaction_timeout *ctx, - unsigned int index) + unsigned int index) { struct _transaction_timeout_peer *pctx; @@ -3436,25 +3489,27 @@ test_client_transaction_timeout_submit(struct _transaction_timeout *ctx, pctx->context = ctx; pctx->index = index; - pctx->conn = smtp_client_connection_create(smtp_client, - SMTP_PROTOCOL_SMTP, net_ip2addr(&bind_ip), bind_ports[index], + pctx->conn = smtp_client_connection_create( + smtp_client, SMTP_PROTOCOL_SMTP, + net_ip2addr(&bind_ip), bind_ports[index], SMTP_CLIENT_SSL_MODE_NONE, NULL); - pctx->trans = smtp_client_transaction_create(pctx->conn, - &((struct smtp_address){.localpart = "sender", - .domain = "example.com"}), NULL, 0, + pctx->trans = smtp_client_transaction_create( + pctx->conn, &((struct smtp_address){ + .localpart = "sender", + .domain = "example.com"}), NULL, 0, test_client_transaction_timeout_finished, pctx); smtp_client_transaction_set_timeout(pctx->trans, 1000); - smtp_client_transaction_start(pctx->trans, - test_client_transaction_timeout_mail_from_cb, pctx); + smtp_client_transaction_start( + pctx->trans, test_client_transaction_timeout_mail_from_cb, + pctx); smtp_client_connection_unref(&pctx->conn); - pctx->to = timeout_add_short(500, - test_client_transaction_timeout_submit1, pctx); + pctx->to = timeout_add_short( + 500, test_client_transaction_timeout_submit1, pctx); } static bool -test_client_transaction_timeout( - const struct smtp_client_settings *client_set) +test_client_transaction_timeout(const struct smtp_client_settings *client_set) { struct _transaction_timeout *ctx; unsigned int i; @@ -3480,8 +3535,8 @@ static void test_transaction_timeout(void) test_begin("transaction timeout"); test_run_client_server(&smtp_client_set, - test_client_transaction_timeout, - test_server_transaction_timeout, 6, NULL); + test_client_transaction_timeout, + test_server_transaction_timeout, 6, NULL); test_end(); } @@ -3519,8 +3574,7 @@ static void (*const test_functions[])(void) = { * Test client */ -static void -test_client_defaults(struct smtp_client_settings *smtp_set) +static void test_client_defaults(struct smtp_client_settings *smtp_set) { /* client settings */ i_zero(smtp_set); @@ -3528,8 +3582,7 @@ test_client_defaults(struct smtp_client_settings *smtp_set) smtp_set->debug = debug; } -static void -test_client_progress_timeout(void *context ATTR_UNUSED) +static void test_client_progress_timeout(void *context ATTR_UNUSED) { /* Terminate test due to lack of progress */ test_assert(FALSE); @@ -3546,7 +3599,7 @@ test_client_init(test_client_init_t client_test, return FALSE; to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000, - test_client_progress_timeout, NULL); + test_client_progress_timeout, NULL); return TRUE; } @@ -3592,12 +3645,15 @@ server_connection_input(struct connection *_conn) size_t size; int ret; - if (conn->dot_input == NULL) - conn->dot_input = i_stream_create_dot(conn->conn.input, TRUE); - while ((ret=i_stream_read_more(conn->dot_input, - &data, &size)) > 0) { + if (conn->dot_input == NULL) { + conn->dot_input = i_stream_create_dot( + conn->conn.input, TRUE); + } + while ((ret = i_stream_read_more(conn->dot_input, + &data, &size)) > 0) { if (test_server_input_data != NULL) { - if (test_server_input_data(conn, data, size) < 0) + if (test_server_input_data( + conn, data, size) < 0) return; } i_stream_skip(conn->dot_input, size); @@ -3612,7 +3668,8 @@ server_connection_input(struct connection *_conn) return; } - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "250 2.0.0 Ok: queued as 73BDE342129\r\n"); conn->state = SERVER_CONNECTION_STATE_MAIL_FROM; continue; @@ -3621,13 +3678,13 @@ server_connection_input(struct connection *_conn) line = i_stream_read_next_line(conn->conn.input); if (line == NULL) { if (conn->conn.input->eof || - conn->conn.input->stream_errno != 0) + conn->conn.input->stream_errno != 0) server_connection_deinit(&conn); return; } if (test_server_input_line != NULL) { - if ((ret=test_server_input_line(conn, line)) < 0) + if ((ret = test_server_input_line(conn, line)) < 0) return; if (ret > 0) continue; @@ -3636,30 +3693,31 @@ server_connection_input(struct connection *_conn) switch (conn->state) { case SERVER_CONNECTION_STATE_EHLO: o_stream_nsend_str(conn->conn.output, - "250-testserver\r\n" - "250-PIPELINING\r\n" - "250-ENHANCEDSTATUSCODES\r\n" - "250 DSN\r\n"); + "250-testserver\r\n" + "250-PIPELINING\r\n" + "250-ENHANCEDSTATUSCODES\r\n" + "250 DSN\r\n"); conn->state = SERVER_CONNECTION_STATE_MAIL_FROM; return; case SERVER_CONNECTION_STATE_MAIL_FROM: if (str_begins(line, "AUTH ")) { - o_stream_nsend_str(conn->conn.output, - "235 2.7.0 " + o_stream_nsend_str( + conn->conn.output, "235 2.7.0 " "Authentication successful\r\n"); continue; } o_stream_nsend_str(conn->conn.output, - "250 2.1.0 Ok\r\n"); + "250 2.1.0 Ok\r\n"); conn->state = SERVER_CONNECTION_STATE_RCPT_TO; continue; case SERVER_CONNECTION_STATE_RCPT_TO: o_stream_nsend_str(conn->conn.output, - "250 2.1.5 Ok\r\n"); + "250 2.1.5 Ok\r\n"); conn->state = SERVER_CONNECTION_STATE_DATA; continue; case SERVER_CONNECTION_STATE_DATA: - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "354 End data with .\r\n"); conn->state = SERVER_CONNECTION_STATE_FINISH; continue; @@ -3670,8 +3728,7 @@ server_connection_input(struct connection *_conn) } } -static void -server_connection_init(int fd) +static void server_connection_init(int fd) { struct server_connection *conn; pool_t pool; @@ -3682,8 +3739,8 @@ server_connection_init(int fd) conn = p_new(pool, struct server_connection, 1); conn->pool = pool; - connection_init_server - (server_conn_list, &conn->conn, "server connection", fd, fd); + connection_init_server(server_conn_list, &conn->conn, + "server connection", fd, fd); if (test_server_init != NULL) { if (test_server_init(conn) != 0) @@ -3691,13 +3748,13 @@ server_connection_init(int fd) } if (test_server_input == NULL) { - o_stream_nsend_str(conn->conn.output, + o_stream_nsend_str( + conn->conn.output, "220 testserver ESMTP Testfix (Debian/GNU)\r\n"); } } -static void -server_connection_deinit(struct server_connection **_conn) +static void server_connection_deinit(struct server_connection **_conn) { struct server_connection *conn = *_conn; @@ -3712,8 +3769,7 @@ server_connection_deinit(struct server_connection **_conn) pool_unref(&conn->pool); } -static void -server_connection_destroy(struct connection *_conn) +static void server_connection_destroy(struct connection *_conn) { struct server_connection *conn = (struct server_connection *)_conn; @@ -3721,8 +3777,7 @@ server_connection_destroy(struct connection *_conn) server_connection_deinit(&conn); } -static void -server_connection_accept(void *context ATTR_UNUSED) +static void server_connection_accept(void *context ATTR_UNUSED) { int fd; @@ -3730,9 +3785,8 @@ server_connection_accept(void *context ATTR_UNUSED) fd = net_accept(fd_listen, NULL, NULL); if (fd == -1) return; - if (fd == -2) { + if (fd == -2) i_fatal("test server: accept() failed: %m"); - } server_connection_init(fd); } @@ -3742,12 +3796,12 @@ server_connection_accept(void *context ATTR_UNUSED) static struct connection_settings server_connection_set = { .input_max_size = (size_t)-1, .output_max_size = (size_t)-1, - .client = FALSE + .client = FALSE, }; static const struct connection_vfuncs server_connection_vfuncs = { .destroy = server_connection_destroy, - .input = server_connection_input + .input = server_connection_input, }; static void test_server_run(unsigned int index) @@ -3755,11 +3809,10 @@ static void test_server_run(unsigned int index) server_index = index; /* open server socket */ - io_listen = io_add(fd_listen, - IO_READ, server_connection_accept, NULL); + io_listen = io_add(fd_listen, IO_READ, server_connection_accept, NULL); - server_conn_list = connection_list_init - (&server_connection_set, &server_connection_vfuncs); + server_conn_list = connection_list_init(&server_connection_set, + &server_connection_vfuncs); io_loop_run(ioloop); @@ -3807,12 +3860,12 @@ static void test_servers_kill_all(void) } } -static void test_run_client_server( - const struct smtp_client_settings *client_set, - test_client_init_t client_test, - test_server_init_t server_test, - unsigned int server_tests_count, - test_dns_init_t dns_test) +static void +test_run_client_server(const struct smtp_client_settings *client_set, + test_client_init_t client_test, + test_server_init_t server_test, + unsigned int server_tests_count, + test_dns_init_t dns_test) { unsigned int i; @@ -3841,8 +3894,10 @@ static void test_run_client_server( server_pids[i] = (pid_t)-1; server_pids_count = 0; hostpid_init(); - if (debug) - i_debug("server[%d]: PID=%s", i+1, my_pid); + if (debug) { + i_debug("server[%d]: PID=%s", + i+1, my_pid); + } /* child: server */ ioloop = io_loop_create(); server_test(i); @@ -3850,8 +3905,9 @@ static void test_run_client_server( i_close_fd(&fd_listen); i_free(bind_ports); i_free(server_pids); - /* wait for it to be killed; this way, valgrind will not - object to this process going away inelegantly. */ + /* wait for it to be killed; this way, valgrind + will not object to this process going away + inelegantly. */ sleep(60); exit(1); } @@ -3914,8 +3970,7 @@ static void test_run_client_server( volatile sig_atomic_t terminating = 0; -static void -test_signal_handler(int signo) +static void test_signal_handler(int signo) { if (terminating != 0) raise(signo);