From: Stephan Bosch Date: Sun, 5 Apr 2020 00:22:50 +0000 (+0200) Subject: lib-smtp: Reformat test-smtp-payload.c. X-Git-Tag: 2.3.13~655 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8e707ebebd0cb1e55765ad498d7ba2c838f86f0;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: Reformat test-smtp-payload.c. --- diff --git a/src/lib-smtp/test-smtp-payload.c b/src/lib-smtp/test-smtp-payload.c index 38feb5bd27..5b8eac6460 100644 --- a/src/lib-smtp/test-smtp-payload.c +++ b/src/lib-smtp/test-smtp-payload.c @@ -83,7 +83,7 @@ static void test_files_read_dir(const char *path) break; #endif errno = 0; - if ((dp=readdir(dirp)) == NULL) + if ((dp = readdir(dirp)) == NULL) break; if (*dp->d_name == '.') continue; @@ -113,8 +113,8 @@ static void test_files_read_dir(const char *path) static void test_files_init(void) { /* initialize file array */ - files_pool = pool_alloconly_create - (MEMPOOL_GROWING"smtp_server_request", 4096); + files_pool = pool_alloconly_create( + MEMPOOL_GROWING"smtp_server_request", 4096); p_array_init(&files, files_pool, 512); /* obtain all filenames */ @@ -126,8 +126,7 @@ static void test_files_deinit(void) pool_unref(&files_pool); } -static struct istream * -test_file_open(const char *path) +static struct istream *test_file_open(const char *path) { struct istream *file; int fd; @@ -190,7 +189,7 @@ client_transaction_read_more(struct client_transaction *ctrans) } /* read payload */ - while ((ret=i_stream_read_more(payload, &pdata, &psize)) > 0) { + while ((ret = i_stream_read_more(payload, &pdata, &psize)) > 0) { if (debug) { i_debug("test server: " "got data for [%s] (size=%d)", @@ -198,8 +197,9 @@ client_transaction_read_more(struct client_transaction *ctrans) } /* compare with file on disk */ pleft = psize; - while ((ret=i_stream_read_more - (ctrans->file, &fdata, &fsize)) > 0 && pleft > 0) { + while ((ret = i_stream_read_more(ctrans->file, + &fdata, &fsize)) > 0 && + pleft > 0) { fsize = (fsize > pleft ? pleft : fsize); if (memcmp(pdata, fdata, fsize) != 0) { i_fatal("test server: " @@ -235,7 +235,8 @@ client_transaction_read_more(struct client_transaction *ctrans) i_fatal("test server: " "failed to read transaction payload: %s", i_stream_get_error(payload)); - } if (i_stream_have_bytes_left(ctrans->file)) { + } + if (i_stream_have_bytes_left(ctrans->file)) { if (i_stream_read_more(ctrans->file, &fdata, &fsize) <= 0) fsize = 0; i_fatal("test server: " @@ -261,7 +262,7 @@ client_transaction_read_more(struct client_transaction *ctrans) static void client_transaction_handle_payload(struct client_transaction *ctrans, - const char *path, struct istream *data_input) + const char *path, struct istream *data_input) { struct smtp_server_transaction *trans = ctrans->trans; struct istream *fstream; @@ -291,8 +292,8 @@ client_transaction_handle_payload(struct client_transaction *ctrans, static struct client_transaction * client_transaction_init(struct client *client, - struct smtp_server_cmd_ctx *data_cmd, - struct smtp_server_transaction *trans) + struct smtp_server_cmd_ctx *data_cmd, + struct smtp_server_transaction *trans) { struct client_transaction *ctrans; pool_t pool = trans->pool; @@ -305,8 +306,7 @@ client_transaction_init(struct client *client, return ctrans; } -static void -client_transaction_deinit(struct client_transaction **_ctrans) +static void client_transaction_deinit(struct client_transaction **_ctrans) { struct client_transaction *ctrans = *_ctrans; @@ -318,7 +318,7 @@ client_transaction_deinit(struct client_transaction **_ctrans) static void test_server_conn_trans_free(void *context ATTR_UNUSED, - struct smtp_server_transaction *trans) + struct smtp_server_transaction *trans) { struct client_transaction *ctrans = (struct client_transaction *)trans->context; @@ -327,8 +327,8 @@ test_server_conn_trans_free(void *context ATTR_UNUSED, static int test_server_conn_cmd_rcpt(void *conn_ctx ATTR_UNUSED, - struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, - struct smtp_server_recipient *rcpt) + struct smtp_server_cmd_ctx *cmd ATTR_UNUSED, + struct smtp_server_recipient *rcpt) { if (debug) { i_debug("test server: RCPT TO:%s", @@ -339,10 +339,9 @@ test_server_conn_cmd_rcpt(void *conn_ctx ATTR_UNUSED, } static int -test_server_conn_cmd_data_begin(void *conn_ctx, - struct smtp_server_cmd_ctx *cmd, - struct smtp_server_transaction *trans, - struct istream *data_input) +test_server_conn_cmd_data_begin(void *conn_ctx, struct smtp_server_cmd_ctx *cmd, + struct smtp_server_transaction *trans, + struct istream *data_input) { struct client *client = (struct client *)conn_ctx; const char *fpath = trans->params.envid; @@ -350,24 +349,22 @@ test_server_conn_cmd_data_begin(void *conn_ctx, i_assert(fpath != NULL); - if (debug) { + if (debug) i_debug("test server: DATA (file path = %s)", fpath); - } ctrans = client_transaction_init(client, cmd, trans); - client_transaction_handle_payload - (ctrans, fpath, data_input); + client_transaction_handle_payload(ctrans, fpath, data_input); trans->context = ctrans; return 0; } static int test_server_conn_cmd_data_continue(void *conn_ctx ATTR_UNUSED, - struct smtp_server_cmd_ctx *cmd, - struct smtp_server_transaction *trans) + struct smtp_server_cmd_ctx *cmd, + struct smtp_server_transaction *trans) { struct client_transaction *ctrans = - ( struct client_transaction *)trans->context; + (struct client_transaction *)trans->context; if (debug) i_debug("test server: DATA continue"); @@ -379,8 +376,7 @@ test_server_conn_cmd_data_continue(void *conn_ctx ATTR_UNUSED, /* client connection */ -static void -test_server_connection_destroy(void *context); +static void test_server_connection_destroy(void *context); static const struct smtp_server_callbacks server_callbacks = { @@ -390,7 +386,7 @@ static const struct smtp_server_callbacks server_callbacks = .conn_trans_free = test_server_conn_trans_free, - .conn_destroy = test_server_connection_destroy + .conn_destroy = test_server_connection_destroy, }; static void client_init(int fd) @@ -404,8 +400,9 @@ static void client_init(int fd) client = p_new(pool, struct client, 1); client->pool = pool; - client->smtp_conn = smtp_server_connection_create(smtp_server, - fd, fd, NULL, 0, (test_ssl_mode == TEST_SSL_MODE_IMMEDIATE), + client->smtp_conn = smtp_server_connection_create( + smtp_server, fd, fd, NULL, 0, + (test_ssl_mode == TEST_SSL_MODE_IMMEDIATE), NULL, &server_callbacks, client); smtp_server_connection_start(client->smtp_conn); DLLIST_PREPEND(&clients, client); @@ -419,13 +416,14 @@ static void client_deinit(struct client **_client) DLLIST_REMOVE(&clients, client); - if (client->smtp_conn != NULL) - smtp_server_connection_terminate(&client->smtp_conn, NULL, "deinit"); + if (client->smtp_conn != NULL) { + smtp_server_connection_terminate(&client->smtp_conn, + NULL, "deinit"); + } pool_unref(&client->pool); } -static void -test_server_connection_destroy(void *context) +static void test_server_connection_destroy(void *context) { struct client *client = context; @@ -439,7 +437,7 @@ static void client_accept(void *context ATTR_UNUSED) for (;;) { /* accept new client */ - if ((fd=net_accept(fd_listen, NULL, NULL)) < 0) { + if ((fd = net_accept(fd_listen, NULL, NULL)) < 0) { if (errno == EAGAIN) break; if (errno == ECONNABORTED) @@ -453,12 +451,10 @@ static void client_accept(void *context ATTR_UNUSED) /* */ -static void -test_server_init(const struct smtp_server_settings *server_set) +static void test_server_init(const struct smtp_server_settings *server_set) { /* open server socket */ - io_listen = io_add(fd_listen, - IO_READ, client_accept, NULL); + io_listen = io_add(fd_listen, IO_READ, client_accept, NULL); smtp_server = smtp_server_init(server_set); } @@ -498,8 +494,7 @@ static unsigned int client_files_first, client_files_last; static struct timeout *client_to = NULL; struct timeout *to_client_progress = NULL; -static struct test_client_connection * -test_client_connection_get(void) +static struct test_client_connection *test_client_connection_get(void) { unsigned int i; enum smtp_client_connection_ssl_mode ssl_mode; @@ -533,8 +528,7 @@ test_client_connection_get(void) return &test_conns[i]; } -static struct test_client_transaction * -test_client_transaction_new(void) +static struct test_client_transaction *test_client_transaction_new(void) { struct test_client_transaction *tctrans; @@ -557,8 +551,7 @@ test_client_transaction_destroy(struct test_client_transaction *tctrans) static void test_client_continue(void *dummy); -static void -test_client_finished(unsigned int files_idx) +static void test_client_finished(unsigned int files_idx) { const char **paths; unsigned int count; @@ -587,7 +580,7 @@ test_client_transaction_finish(struct test_client_transaction *tctrans) static void test_client_transaction_rcpt(const struct smtp_reply *reply, - struct test_client_transaction *tctrans) + struct test_client_transaction *tctrans) { const char **paths; const char *path; @@ -611,7 +604,7 @@ test_client_transaction_rcpt(const struct smtp_reply *reply, static void test_client_transaction_rcpt_data(const struct smtp_reply *reply ATTR_UNUSED, - struct test_client_transaction *tctrans) + struct test_client_transaction *tctrans) { const char **paths; const char *path; @@ -635,7 +628,7 @@ test_client_transaction_rcpt_data(const struct smtp_reply *reply ATTR_UNUSED, static void test_client_transaction_data(const struct smtp_reply *reply, - struct test_client_transaction *tctrans) + struct test_client_transaction *tctrans) { const char **paths; const char *path; @@ -691,8 +684,8 @@ static void test_client_continue(void *dummy ATTR_UNUSED) i_assert(client_files_last <= count); i_assert(client_files_first <= client_files_last); - for (; client_files_first < client_files_last && - paths[client_files_first] == NULL; client_files_first++); + for (; (client_files_first < client_files_last && + paths[client_files_first] == NULL); client_files_first++); pending_count = 0; for (i = client_files_first; i < client_files_last; i++) { @@ -734,8 +727,10 @@ static void test_client_continue(void *dummy ATTR_UNUSED) "skipping %s [%u]", path, client_files_last); } - if (client_to == NULL) - client_to = timeout_add_short(0, test_client_continue, NULL); + if (client_to == NULL) { + client_to = timeout_add_short( + 0, test_client_continue, NULL); + } continue; } @@ -764,16 +759,19 @@ static void test_client_continue(void *dummy ATTR_UNUSED) smtp_client_transaction_add_rcpt( tctrans->conn->trans, smtp_address_create_temp( - t_strdup_printf("rcpt%u", r), "example.com"), NULL, + t_strdup_printf("rcpt%u", r), + "example.com"), NULL, test_client_transaction_rcpt, test_client_transaction_rcpt_data, tctrans); } - if (!test_unknown_size) - payload = i_stream_create_base64_encoder(fstream, 80, TRUE); - else { + if (!test_unknown_size) { + payload = i_stream_create_base64_encoder( + fstream, 80, TRUE); + } else { struct istream *b64_stream = - i_stream_create_base64_encoder(fstream, 80, FALSE); + i_stream_create_base64_encoder( + fstream, 80, FALSE); payload = i_stream_create_crlf(b64_stream); i_stream_unref(&b64_stream); } @@ -797,8 +795,7 @@ static void test_client_continue(void *dummy ATTR_UNUSED) } } -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 */ failure = "Test is hanging"; @@ -808,12 +805,13 @@ test_client_progress_timeout(void *context ATTR_UNUSED) static void test_client(enum smtp_protocol protocol, - const struct smtp_client_settings *client_set) + const struct smtp_client_settings *client_set) { client_protocol = protocol; if (!small_socket_buffers) { - to_client_progress = timeout_add(CLIENT_PROGRESS_TIMEOUT*1000, + to_client_progress = timeout_add( + CLIENT_PROGRESS_TIMEOUT*1000, test_client_progress_timeout, NULL); } @@ -864,12 +862,13 @@ static void test_server_kill(void) server_pid = (pid_t)-1; } -static void test_run_client_server( +static void +test_run_client_server( enum smtp_protocol protocol, struct smtp_client_settings *client_set, struct smtp_server_settings *server_set, void (*client_init)(enum smtp_protocol protocol, - const struct smtp_client_settings *client_set)) + const struct smtp_client_settings *client_set)) { struct ioloop *ioloop; @@ -911,10 +910,12 @@ static void test_run_client_server( } } -static void test_run_scenarios(enum smtp_protocol protocol, +static void +test_run_scenarios( + enum smtp_protocol protocol, enum smtp_capability capabilities, void (*client_init)(enum smtp_protocol protocol, - const struct smtp_client_settings *client_set)) + const struct smtp_client_settings *client_set)) { struct smtp_server_settings smtp_server_set; struct smtp_client_settings smtp_client_set; @@ -957,9 +958,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = FALSE; test_ssl_mode = TEST_SSL_MODE_NONE; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("sequential", (failure == NULL), failure); @@ -968,9 +968,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = FALSE; test_ssl_mode = TEST_SSL_MODE_NONE; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("parallel", (failure == NULL), failure); @@ -981,9 +980,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = FALSE; test_ssl_mode = TEST_SSL_MODE_NONE; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("parallel pipelining", (failure == NULL), failure); @@ -994,9 +992,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = TRUE; test_ssl_mode = TEST_SSL_MODE_NONE; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("unknown payload size", (failure == NULL), failure); @@ -1008,9 +1005,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = FALSE; test_ssl_mode = TEST_SSL_MODE_IMMEDIATE; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("parallel pipelining ssl", @@ -1022,9 +1018,8 @@ static void test_run_scenarios(enum smtp_protocol protocol, test_unknown_size = FALSE; test_ssl_mode = TEST_SSL_MODE_STARTTLS; test_files_init(); - test_run_client_server(protocol, - &smtp_client_set, &smtp_server_set, - client_init); + test_run_client_server(protocol, &smtp_client_set, &smtp_server_set, + client_init); test_files_deinit(); test_out_reason("parallel pipelining startls", @@ -1036,7 +1031,7 @@ static void test_smtp_normal(void) { test_begin("smtp payload - normal"); test_run_scenarios(SMTP_PROTOCOL_SMTP, - SMTP_CAPABILITY_DSN, test_client); + SMTP_CAPABILITY_DSN, test_client); test_end(); } @@ -1044,8 +1039,8 @@ static void test_smtp_chunking(void) { test_begin("smtp payload - chunking"); test_run_scenarios(SMTP_PROTOCOL_SMTP, - SMTP_CAPABILITY_DSN | SMTP_CAPABILITY_CHUNKING, - test_client); + SMTP_CAPABILITY_DSN | SMTP_CAPABILITY_CHUNKING, + test_client); test_end(); } @@ -1053,7 +1048,7 @@ static void test_lmtp_normal(void) { test_begin("lmtp payload - normal"); test_run_scenarios(SMTP_PROTOCOL_LMTP, - SMTP_CAPABILITY_DSN, test_client); + SMTP_CAPABILITY_DSN, test_client); test_end(); } @@ -1061,8 +1056,8 @@ static void test_lmtp_chunking(void) { test_begin("lmtp payload - chunking"); test_run_scenarios(SMTP_PROTOCOL_LMTP, - SMTP_CAPABILITY_DSN | SMTP_CAPABILITY_CHUNKING, - test_client); + SMTP_CAPABILITY_DSN | SMTP_CAPABILITY_CHUNKING, + test_client); test_end(); } @@ -1080,8 +1075,7 @@ static void (*const test_functions[])(void) = { 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);