doveadm-zlib.c revision 43a6cdb3561dcfc5950542ce62509a7747a977ae
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainenstatic bool test_dump_imapzlib(const char *path)
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen const char *p;
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen if (p == NULL || (strcmp(p, ".in") != 0 && strcmp(p, ".out") != 0))
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen match = strstr(buf, " ok begin compression.") != NULL ||
8d587838c414c48a331f0b54cd7ffd97e5024abdTimo Sirainenstatic void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen const unsigned char *data;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen input = i_stream_create_fd_autoclose(&fd, 1024*32);
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen while ((line = i_stream_read_next_line(input)) != NULL) {
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen /* skip tag */
c649139f889c02154fc9a153728b81619edb5663Timo Sirainen if (strncmp(line, "OK Begin compression", 20) == 0 ||
2d7df7973f80011033e8e9fa676d3ff4c14468d8Stephan Bosch input2 = i_stream_create_deflate(input, TRUE);
2d7df7973f80011033e8e9fa676d3ff4c14468d8Stephan Bosch while (i_stream_read_more(input2, &data, &size) != -1) {
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainenstatic void client_input(struct client *client)
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen /* start compression */
526631052ca3175357302af8fa7dcbf763b40c53Stephan Bosch input = i_stream_create_deflate(client->input, TRUE);
526631052ca3175357302af8fa7dcbf763b40c53Stephan Bosch output = o_stream_create_deflate(client->output, 6);
c649139f889c02154fc9a153728b81619edb5663Timo Sirainenstatic void server_input(struct client *client)
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen const unsigned char *data;
efe78d3ba24fc866af1c79b9223dc0809ba26cadStephan Bosch data = i_stream_get_data(client->input, &size);
88b90ce9dfe1056d1ec5497b95592d30a849e5f1Timo Sirainenstatic void cmd_zlibconnect(int argc ATTR_UNUSED, char *argv[])
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen (argv[2] != NULL && net_str2port(argv[2], &port) < 0))
2d7df7973f80011033e8e9fa676d3ff4c14468d8Stephan Bosch ret = net_gethostbyname(argv[1], &ips, &ips_count);
f7fa93fb42a5b9d4a7e2f0367f03f920ef7ec443Timo Sirainen if ((fd = net_connect_ip(&ips[0], port, NULL)) == -1)
f7fa93fb42a5b9d4a7e2f0367f03f920ef7ec443Timo Sirainen i_fatal("connect(%s, %u) failed: %m", argv[1], port);
dafbec2c6b4275233a78cb137f41dd8041aa1c46Timo Sirainen i_info("Connected to %s port %u. Ctrl-D starts compression",
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen client.input = i_stream_create_fd(fd, (size_t)-1);
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen o_stream_set_no_error_handling(client.output, TRUE);
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen client.io_client = io_add(STDIN_FILENO, IO_READ, client_input, &client);
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen client.io_server = io_add(fd, IO_READ, server_input, &client);
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainenstatic void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen i_fatal("Dovecot compiled without zlib support");
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainenstatic void cmd_zlibconnect(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen i_fatal("Dovecot compiled without zlib support");
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainenstruct doveadm_cmd_dump doveadm_cmd_dump_zlib = {
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen "zlibconnect",
48566ca412a7cf3b42512fd0ec112744778e5da0Timo Sirainen "<host> [<port>]"