struct stat st;
errno = 0;
- if ((dp=readdir(dirp)) == NULL)
+ if ((dp = readdir(dirp)) == NULL)
break;
if (*dp->d_name == '.' ||
dp->d_name[strcspn(dp->d_name, unsafe_characters)] != '\0')
static void test_files_init(void)
{
/* initialize file array */
- files_pool = pool_alloconly_create
- (MEMPOOL_GROWING"http_server_request", 4096);
+ files_pool = pool_alloconly_create(
+ MEMPOOL_GROWING"http_server_request", 4096);
p_array_init(&files, files_pool, 512);
/* obtain all filenames */
}
static struct istream *
-test_file_open(const char *path,
- unsigned int *status_r, const char **reason_r)
- ATTR_NULL(2, 3)
+test_file_open(const char *path, unsigned int *status_r, const char **reason_r)
+ ATTR_NULL(2, 3)
{
int fd;
/* location: /succes */
-static void
-client_handle_success_request(struct client_request *creq)
+static void client_handle_success_request(struct client_request *creq)
{
struct http_server_request *req = creq->server_req;
const struct http_request *hreq =
/* location: /download/... */
static void
-client_handle_download_request(
- struct client_request *creq,
- const char *path)
+client_handle_download_request(struct client_request *creq,
+ const char *path)
{
struct http_server_request *req = creq->server_req;
const struct http_request *hreq =
if (blocking) {
output = http_server_response_get_payload_output(resp, TRUE);
- if (o_stream_send_istream(output, fstream) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
+ if (o_stream_send_istream(output, fstream) !=
+ OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
i_fatal("test server: download: "
"failed to send blocking file payload");
}
/* location: /echo */
-static void
-client_request_finish_payload_in(struct client_request *creq)
+static void client_request_finish_payload_in(struct client_request *creq)
{
struct http_server_response *resp;
struct istream *payload_input;
- payload_input = iostream_temp_finish(&creq->payload_output, 4096);
+ payload_input =
+ iostream_temp_finish(&creq->payload_output, 4096);
- resp = http_server_response_create
- (creq->server_req, 200, "OK");
+ resp = http_server_response_create(creq->server_req, 200, "OK");
http_server_response_add_header(resp, "Content-Type", "text/plain");
http_server_response_set_payload(resp, payload_input);
http_server_response_submit(resp);
i_stream_unref(&payload_input);
}
-static void
-client_request_read_echo(struct client_request *creq)
+static void client_request_read_echo(struct client_request *creq)
{
enum ostream_send_istream_result res;
return;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
i_fatal("test server: echo: "
- "Failed to read all echo payload [%s]", creq->path);
+ "Failed to read all echo payload [%s]",
+ creq->path);
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
i_fatal("test server: echo: "
- "Failed to write all echo payload [%s]", creq->path);
+ "Failed to write all echo payload [%s]",
+ creq->path);
}
client_request_finish_payload_in(creq);
i_stream_unref(&creq->payload_input);
}
-static void
-client_request_read_echo_more(struct client_request *creq)
+static void client_request_read_echo_more(struct client_request *creq)
{
client_request_read_echo(creq);
if (debug) {
i_debug("test server: echo: "
- "finished receiving payload for %s", creq->path);
+ "finished receiving payload for %s",
+ creq->path);
}
}
static void
client_handle_echo_request(struct client_request *creq,
- const char *path)
+ const char *path)
{
struct http_server_request *req = creq->server_req;
const struct http_request *hreq =
struct ostream *payload_output;
uoff_t size;
- creq->path = p_strdup
- (http_server_request_get_pool(req), path);
+ creq->path = p_strdup(http_server_request_get_pool(req), path);
if (strcmp(hreq->method, "PUT") != 0) {
http_server_request_fail(req,
size = 0;
(void)http_request_get_payload_size(hreq, &size);
if (size == 0) {
- resp = http_server_response_create
- (creq->server_req, 200, "OK");
- http_server_response_add_header(resp, "Content-Type", "text/plain");
+ resp = http_server_response_create(creq->server_req, 200, "OK");
+ http_server_response_add_header(resp,
+ "Content-Type", "text/plain");
http_server_response_submit(resp);
return;
}
- payload_output = iostream_temp_create
- ("/tmp/test-http-server", 0);
+ payload_output = iostream_temp_create("/tmp/test-http-server", 0);
if (blocking) {
struct istream *payload_input;
if (read_server_partial > 0) {
struct istream *partial =
- i_stream_create_limit(payload_input, read_server_partial);
+ i_stream_create_limit(payload_input,
+ read_server_partial);
i_stream_unref(&payload_input);
payload_input = partial;
}
- if (o_stream_send_istream(payload_output, payload_input) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
+ if (o_stream_send_istream(payload_output, payload_input) !=
+ OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
i_fatal("test server: echo: "
"failed to receive blocking echo payload");
}
if (debug) {
i_debug("test server: echo: "
- "finished receiving blocking payload for %s", path);
+ "finished receiving blocking payload for %s",
+ path);
}
resp = http_server_response_create(req, 200, "OK");
- http_server_response_add_header(resp, "Content-Type", "text/plain");
+ http_server_response_add_header(resp,
+ "Content-Type", "text/plain");
- payload_output = http_server_response_get_payload_output(resp, TRUE);
- if (o_stream_send_istream(payload_output, payload_input) != OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
+ payload_output =
+ http_server_response_get_payload_output(resp, TRUE);
+ if (o_stream_send_istream(payload_output, payload_input) !=
+ OSTREAM_SEND_ISTREAM_RESULT_FINISHED) {
i_fatal("test server: echo: "
"failed to send blocking echo payload");
}
if (debug) {
i_debug("test server: echo: "
- "finished sending blocking payload for %s", path);
+ "finished sending blocking payload for %s",
+ path);
}
i_stream_unref(&payload_input);
o_stream_close(payload_output);
o_stream_unref(&payload_output);
-
} else {
creq->payload_output = payload_output;
if (read_server_partial > 0) {
struct istream *partial =
- i_stream_create_limit(creq->payload_input, read_server_partial);
+ i_stream_create_limit(creq->payload_input,
+ read_server_partial);
i_stream_unref(&creq->payload_input);
creq->payload_input = partial;
}
static struct client_request *
client_request_init(struct client *client,
- struct http_server_request *req)
+ struct http_server_request *req)
{
struct client_request *creq;
pool_t pool = http_server_request_get_pool(req);
static void
client_handle_request(void *context,
- struct http_server_request *req)
+ struct http_server_request *req)
{
const struct http_request *hreq =
http_server_request_get(req);
if (debug) {
i_debug("test server: "
- "request method=`%s' path=`%s'", hreq->method, path);
+ "request method=`%s' path=`%s'",
+ hreq->method, path);
}
creq = client_request_init(client, req);
return;
}
- if ((p=strchr(path+1, '/')) == NULL) {
+ if ((p = strchr(path+1, '/')) == NULL) {
http_server_request_fail(req, 404, "Not found");
return;
}
/* client connection */
-static void
-client_connection_destroy(void *context, const char *reason);
+static void client_connection_destroy(void *context, const char *reason);
static const struct http_server_callbacks http_callbacks = {
.connection_destroy = client_connection_destroy,
client = p_new(pool, struct client, 1);
client->pool = pool;
- client->http_conn = http_server_connection_create(http_server,
- fd, fd, test_ssl, &http_callbacks, client);
+ client->http_conn = http_server_connection_create(
+ http_server, fd, fd, test_ssl, &http_callbacks, client);
DLLIST_PREPEND(&clients, client);
}
DLLIST_REMOVE(&clients, client);
- if (client->http_conn != NULL)
- http_server_connection_close(&client->http_conn, "deinit");
+ if (client->http_conn != NULL) {
+ http_server_connection_close(&client->http_conn,
+ "deinit");
+ }
pool_unref(&client->pool);
}
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 http_server_settings *server_set)
+static void test_server_init(const struct http_server_settings *server_set)
{
/* open server socket */
io_listen = io_add(fd_listen,
static unsigned int client_files_first, client_files_last;
struct timeout *to_client_progress = NULL;
-static struct test_client_request *
-test_client_request_new(void)
+static struct test_client_request *test_client_request_new(void)
{
struct test_client_request *tcreq;
return tcreq;
}
-static void
-test_client_request_destroy(struct test_client_request *tcreq)
+static void test_client_request_destroy(struct test_client_request *tcreq)
{
io_remove(&tcreq->io);
i_stream_unref(&tcreq->payload);
i_free(tcreq);
}
-static void
-test_client_switch_ioloop(void)
+static void test_client_switch_ioloop(void)
{
struct test_client_request *tcreq;
}
}
-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_download_continue(void);
-static void
-test_client_download_finished(unsigned int files_idx)
+static void test_client_download_finished(unsigned int files_idx)
{
const char **paths;
unsigned int count;
timeout_reset(to_client_progress);
/* 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 client: download: "
"got data for [%u] (size=%d)",
}
/* compare with file on disk */
pleft = psize;
- while ((ret=i_stream_read_more
- (tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
+ while ((ret = i_stream_read_more(tcreq->file,
+ &fdata, &fsize)) > 0 &&
+ pleft > 0) {
fsize = (fsize > pleft ? pleft : fsize);
if (memcmp(pdata, fdata, fsize) != 0) {
i_fatal("test client: download: "
"received data does not match file "
"(%"PRIuUOFF_T":%"PRIuUOFF_T")",
- payload->v_offset, tcreq->file->v_offset);
+ payload->v_offset,
+ tcreq->file->v_offset);
}
i_stream_skip(tcreq->file, fsize);
pleft -= fsize;
}
if (ret < 0 && tcreq->file->stream_errno != 0) {
i_fatal("test client: download: "
- "failed to read file: %s", i_stream_get_error(tcreq->file));
+ "failed to read file: %s",
+ i_stream_get_error(tcreq->file));
}
i_stream_skip(payload, psize);
}
static void
test_client_download_response(const struct http_response *resp,
- struct test_client_request *tcreq)
+ struct test_client_request *tcreq)
{
const char **paths;
const char *path;
if (status != resp->status) {
i_fatal("test client: download: "
- "got wrong response for %s: %u %s (expected: %u %s)",
- path, resp->status, resp->reason, status, reason);
+ "got wrong response for %s: %u %s "
+ "(expected: %u %s)", path,
+ resp->status, resp->reason, status, reason);
}
if (resp->status / 100 != 2) {
tcreq->file = fstream;
} else {
struct istream *payload = resp->payload;
- tcreq->payload = i_stream_create_limit
- (payload, read_client_partial);
- tcreq->file = i_stream_create_limit
- (fstream, read_client_partial);
+ tcreq->payload = i_stream_create_limit(payload,
+ read_client_partial);
+ tcreq->file = i_stream_create_limit(fstream,
+ read_client_partial);
i_stream_unref(&fstream);
}
return;
}
- for (; client_files_last < count &&
- (client_files_last - client_files_first) < test_max_pending;
- client_files_last++) {
+ for (; (client_files_last < count &&
+ (client_files_last - client_files_first) < test_max_pending);
+ client_files_last++) {
struct http_client *http_client =
http_clients[client_files_last % parallel_clients];
const char *path = paths[client_files_last];
}
}
-static void
-test_client_download(const struct http_client_settings *client_set)
+static void test_client_download(const struct http_client_settings *client_set)
{
/* create client(s) */
test_client_create_clients(client_set);
static void test_client_echo_continue(void);
-static void
-test_client_echo_finished(unsigned int files_idx)
+static void test_client_echo_finished(unsigned int files_idx)
{
const char **paths;
unsigned int count;
test_client_echo_continue();
}
-static void
-test_client_echo_payload_input(struct test_client_request *tcreq)
+static void test_client_echo_payload_input(struct test_client_request *tcreq)
{
struct istream *payload = tcreq->payload;
const unsigned char *pdata, *fdata;
timeout_reset(to_client_progress);
/* 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 client: echo: "
"got data for [%u] (size=%d)",
}
/* compare with file on disk */
pleft = psize;
- while ((ret=i_stream_read_more
- (tcreq->file, &fdata, &fsize)) > 0 && pleft > 0) {
+ while ((ret = i_stream_read_more(tcreq->file,
+ &fdata, &fsize)) > 0 &&
+ pleft > 0) {
fsize = (fsize > pleft ? pleft : fsize);
if (memcmp(pdata, fdata, fsize) != 0) {
i_fatal("test client: echo: "
"received data does not match file "
"(%"PRIuUOFF_T":%"PRIuUOFF_T")",
- payload->v_offset, tcreq->file->v_offset);
+ payload->v_offset,
+ tcreq->file->v_offset);
}
i_stream_skip(tcreq->file, fsize);
pleft -= fsize;
}
if (ret < 0 && tcreq->file->stream_errno != 0) {
i_fatal("test client: echo: "
- "failed to read file: %s", i_stream_get_error(tcreq->file));
+ "failed to read file: %s",
+ i_stream_get_error(tcreq->file));
}
i_stream_skip(payload, psize);
}
static void
test_client_echo_response(const struct http_response *resp,
- struct test_client_request *tcreq)
+ struct test_client_request *tcreq)
{
const char **paths;
const char *path;
}
if (read_server_partial > 0) {
- struct istream *partial = i_stream_create_limit
- (fstream, read_server_partial);
+ struct istream *partial =
+ i_stream_create_limit(fstream, read_server_partial);
i_stream_unref(&fstream);
fstream = partial;
}
if (debug) {
i_debug("test client: echo: "
- "received until [%u/%u]", client_files_first-1, count);
+ "received until [%u/%u]",
+ client_files_first-1, count);
}
if (debug && client_files_first < count) {
const char *path = paths[client_files_first];
i_debug("test client: echo: "
"next blocking: %s [%d]",
- (path == NULL ? "none" : path),
- client_files_first);
+ (path == NULL ? "none" : path), client_files_first);
}
if (client_files_first >= count) {
}
first_submitted = client_files_last;
- for (; client_files_last < count &&
- (client_files_last - client_files_first) < test_max_pending;
- client_files_last++) {
+ for (; (client_files_last < count &&
+ (client_files_last - client_files_first) < test_max_pending);
+ client_files_last++) {
struct http_client *http_client =
http_clients[client_files_last % parallel_clients];
struct istream *fstream;
test_client_echo_response, tcreq);
http_client_request_set_port(hreq, bind_port);
http_client_request_set_ssl(hreq, test_ssl);
- http_client_request_set_payload
- (hreq, fstream, request_100_continue);
+ http_client_request_set_payload(hreq, fstream,
+ request_100_continue);
http_client_request_set_destroy_callback(hreq,
test_client_request_destroy, tcreq);
http_client_request_submit(hreq);
if (i == ioloop_nested_last)
io_loop_stop(ioloop_nested);
} else if (client_ioloop_nesting > 0 &&
- ((client_files_last / client_ioloop_nesting) !=
- (first_submitted / client_ioloop_nesting)) ) {
+ ((client_files_last / client_ioloop_nesting) !=
+ (first_submitted / client_ioloop_nesting))) {
struct ioloop *prev_ioloop = current_ioloop;
unsigned int i;
ioloop_nested_last = client_files_last;
if (debug) {
- i_debug("test client: echo: entering ioloop for %u...%u (depth=%u)",
- ioloop_nested_first, ioloop_nested_last, ioloop_nested_depth);
+ i_debug("test client: echo: entering ioloop for %u...%u "
+ "(depth=%u)", ioloop_nested_first,
+ ioloop_nested_last, ioloop_nested_depth);
}
ioloop_nested_depth++;
ioloop_nested_depth--;
if (debug) {
- i_debug("test client: echo: leaving ioloop for %u...%u (depth=%u)",
- ioloop_nested_first, ioloop_nested_last, ioloop_nested_depth);
+ i_debug("test client: echo: leaving ioloop for %u...%u "
+ "(depth=%u)", ioloop_nested_first,
+ ioloop_nested_last, ioloop_nested_depth);
}
ioloop_nested_first = ioloop_nested_last = 0;
}
}
-static void
-test_client_echo(const struct http_client_settings *client_set)
+static void test_client_echo(const struct http_client_settings *client_set)
{
/* create client */
test_client_create_clients(client_set);
}
}
-static void test_run_sequential(
+static void
+test_run_sequential(
void (*client_init)(const struct http_client_settings *client_set))
{
struct http_server_settings http_server_set;
http_client_set.debug = debug;
test_files_init();
- test_run_client_server
- (&http_client_set, &http_server_set, client_init);
+ test_run_client_server(&http_client_set, &http_server_set, client_init);
test_files_deinit();
test_out_reason("sequential", (failure == NULL), failure);
}
-static void test_run_pipeline(
+static void
+test_run_pipeline(
void (*client_init)(const struct http_client_settings *client_set))
{
struct http_server_settings http_server_set;
http_client_set.debug = debug;
test_files_init();
- test_run_client_server
- (&http_client_set, &http_server_set, client_init);
+ test_run_client_server(&http_client_set, &http_server_set, client_init);
test_files_deinit();
test_out_reason("pipeline", (failure == NULL), failure);
}
-static void test_run_parallel(
+static void
+test_run_parallel(
void (*client_init)(const struct http_client_settings *client_set))
{
struct http_server_settings http_server_set;
http_client_set.debug = debug;
test_files_init();
- test_run_client_server
- (&http_client_set, &http_server_set, client_init);
+ test_run_client_server(&http_client_set, &http_server_set, client_init);
test_files_deinit();
test_out_reason("parallel", (failure == NULL), failure);
static void test_echo_server_nonblocking(void)
{
- test_begin("http payload echo (server non-blocking)");
+ test_begin("http payload echo "
+ "(server non-blocking)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; low-level)");
+ test_begin("http payload echo "
+ "(server non-blocking; low-level)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; handler)");
+ test_begin("http payload echo "
+ "(server non-blocking; handler)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
static void test_echo_server_nonblocking_sync(void)
{
- test_begin("http payload echo (server non-blocking; 100-continue)");
+ test_begin("http payload echo "
+ "(server non-blocking; 100-continue)");
blocking = FALSE;
request_100_continue = TRUE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; 100-continue; low-level)");
+ test_begin("http payload echo "
+ "(server non-blocking; 100-continue; low-level)");
blocking = FALSE;
request_100_continue = TRUE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; 100-continue; handler)");
+ test_begin("http payload echo "
+ "(server non-blocking; 100-continue; handler)");
blocking = FALSE;
request_100_continue = TRUE;
test_unknown_size = FALSE;
static void test_echo_server_nonblocking_partial(void)
{
- test_begin("http payload echo (server non-blocking; partial short)");
+ test_begin("http payload echo "
+ "(server non-blocking; partial short)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_pipeline(test_client_echo);
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; partial long)");
+ test_begin("http payload echo "
+ "(server non-blocking; partial long)");
read_server_partial = IO_BLOCK_SIZE + 1024;
test_run_sequential(test_client_echo);
test_run_pipeline(test_client_echo);
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; partial short; low-level)");
+ test_begin("http payload echo (server non-blocking; "
+ "partial short; low-level)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_pipeline(test_client_echo);
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; partial long; low-level)");
+ test_begin("http payload echo "
+ "(server non-blocking; partial long; low-level)");
read_server_partial = IO_BLOCK_SIZE + 1024;
test_run_sequential(test_client_echo);
test_run_pipeline(test_client_echo);
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; partial short; handler)");
+ test_begin("http payload echo "
+ "(server non-blocking; partial short; handler)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_pipeline(test_client_echo);
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; partial long; handler)");
+ test_begin("http payload echo "
+ "(server non-blocking; partial long; handler)");
read_server_partial = IO_BLOCK_SIZE + 1024;
test_run_sequential(test_client_echo);
test_run_pipeline(test_client_echo);
static void test_echo_client_shared(void)
{
- test_begin("http payload download (server non-blocking; client shared)");
+ test_begin("http payload download "
+ "(server non-blocking; client shared)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_download);
test_end();
- test_begin("http payload download (server blocking; client shared)");
+ test_begin("http payload download "
+ "(server blocking; client shared)");
blocking = TRUE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_download);
test_end();
- test_begin("http payload echo (server non-blocking; client shared)");
+ test_begin("http payload echo "
+ "(server non-blocking; client shared)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server blocking; client shared)");
+ test_begin("http payload echo "
+ "(server blocking; client shared)");
blocking = TRUE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
test_run_parallel(test_client_echo);
test_end();
- test_begin("http payload echo (server non-blocking; client global)");
+ test_begin("http payload echo "
+ "(server non-blocking; client global)");
blocking = FALSE;
request_100_continue = FALSE;
test_unknown_size = FALSE;
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);