break;
#endif
errno = 0;
- if ((dp=readdir(dirp)) == NULL)
+ if ((dp = readdir(dirp)) == NULL)
break;
if (*dp->d_name == '.')
continue;
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 */
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;
}
/* 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)",
}
/* 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: "
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: "
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;
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;
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;
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;
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",
}
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;
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");
/* 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 =
{
.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)
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);
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;
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)
/* */
-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);
}
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;
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;
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;
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;
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;
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;
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++) {
"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;
}
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);
}
}
}
-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";
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);
}
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;
}
}
-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;
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);
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);
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);
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);
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",
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",
{
test_begin("smtp payload - normal");
test_run_scenarios(SMTP_PROTOCOL_SMTP,
- SMTP_CAPABILITY_DSN, test_client);
+ SMTP_CAPABILITY_DSN, test_client);
test_end();
}
{
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();
}
{
test_begin("lmtp payload - normal");
test_run_scenarios(SMTP_PROTOCOL_LMTP,
- SMTP_CAPABILITY_DSN, test_client);
+ SMTP_CAPABILITY_DSN, test_client);
test_end();
}
{
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();
}
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);