doveadm-zlib.c (dovecot-2.3.16) | : | doveadm-zlib.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 45 | skipping to change at line 45 | |||
buf[ret] = '\0'; | buf[ret] = '\0'; | |||
(void)str_lcase(buf); | (void)str_lcase(buf); | |||
match = strstr(buf, " ok begin compression.") != NULL || | match = strstr(buf, " ok begin compression.") != NULL || | |||
strstr(buf, " compress deflate") != NULL; | strstr(buf, " compress deflate") != NULL; | |||
} | } | |||
i_close_fd(&fd); | i_close_fd(&fd); | |||
return match; | return match; | |||
} | } | |||
#ifdef HAVE_ZLIB | #ifdef HAVE_ZLIB | |||
static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[]) | static void | |||
cmd_dump_imapzlib(const char *path, const char *const *args ATTR_UNUSED) | ||||
{ | { | |||
struct istream *input, *input2; | struct istream *input, *input2; | |||
const unsigned char *data; | const unsigned char *data; | |||
size_t size; | size_t size; | |||
const char *line; | const char *line; | |||
int fd; | int fd; | |||
fd = open(argv[1], O_RDONLY); | fd = open(path, O_RDONLY); | |||
if (fd < 0) | if (fd < 0) | |||
i_fatal("open(%s) failed: %m", argv[1]); | i_fatal("open(%s) failed: %m", path); | |||
input = i_stream_create_fd_autoclose(&fd, 1024*32); | input = i_stream_create_fd_autoclose(&fd, 1024*32); | |||
while ((line = i_stream_read_next_line(input)) != NULL) { | while ((line = i_stream_read_next_line(input)) != NULL) { | |||
/* skip tag */ | /* skip tag */ | |||
printf("%s\r\n", line); | printf("%s\r\n", line); | |||
while (*line != ' ' && *line != '\0') line++; | while (*line != ' ' && *line != '\0') line++; | |||
if (*line == '\0') | if (*line == '\0') | |||
continue; | continue; | |||
line++; | line++; | |||
if (str_begins(line, "OK Begin compression") || | if (str_begins(line, "OK Begin compression") || | |||
skipping to change at line 78 | skipping to change at line 79 | |||
} | } | |||
input2 = i_stream_create_deflate(input); | input2 = i_stream_create_deflate(input); | |||
i_stream_unref(&input); | i_stream_unref(&input); | |||
while (i_stream_read_more(input2, &data, &size) != -1) { | while (i_stream_read_more(input2, &data, &size) != -1) { | |||
if (fwrite(data, 1, size, stdout) != size) | if (fwrite(data, 1, size, stdout) != size) | |||
break; | break; | |||
i_stream_skip(input2, size); | i_stream_skip(input2, size); | |||
} | } | |||
if (input2->stream_errno != 0) { | if (input2->stream_errno != 0) | |||
i_error("read(%s) failed: %s", | i_error("read(%s) failed: %s", path, i_stream_get_error(input)); | |||
argv[1], i_stream_get_error(input)); | ||||
} | ||||
i_stream_unref(&input2); | i_stream_unref(&input2); | |||
fflush(stdout); | fflush(stdout); | |||
} | } | |||
struct client { | struct client { | |||
int fd; | int fd; | |||
struct io *io_client, *io_server; | struct io *io_client, *io_server; | |||
struct istream *input, *stdin_input; | struct istream *input, *stdin_input; | |||
struct ostream *output; | struct ostream *output; | |||
const struct compression_handler *handler; | const struct compression_handler *handler; | |||
skipping to change at line 223 | skipping to change at line 222 | |||
client->compress_waiting = FALSE; | client->compress_waiting = FALSE; | |||
i_stream_set_input_pending(client->stdin_input, TRUE); | i_stream_set_input_pending(client->stdin_input, TRUE); | |||
} | } | |||
data = i_stream_get_data(client->input, &size); | data = i_stream_get_data(client->input, &size); | |||
if (write(STDOUT_FILENO, data, size) < 0) | if (write(STDOUT_FILENO, data, size) < 0) | |||
i_fatal("write(stdout) failed: %m"); | i_fatal("write(stdout) failed: %m"); | |||
i_stream_skip(client->input, size); | i_stream_skip(client->input, size); | |||
} | } | |||
static void cmd_zlibconnect(int argc ATTR_UNUSED, char *argv[]) | static void cmd_zlibconnect(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
struct client client; | struct client client; | |||
const char *host; | ||||
struct ip_addr *ips; | struct ip_addr *ips; | |||
unsigned int ips_count; | unsigned int ips_count; | |||
int64_t port_int64; | ||||
in_port_t port = 143; | in_port_t port = 143; | |||
int fd, ret; | int fd, ret; | |||
if (argv[1] == NULL || | if (!doveadm_cmd_param_str(cctx, "host", &host)) | |||
(argv[2] != NULL && net_str2port(argv[2], &port) < 0)) | help_ver2(&doveadm_cmd_zlibconnect); | |||
help(&doveadm_cmd_zlibconnect); | if (doveadm_cmd_param_int64(cctx, "port", &port_int64)) { | |||
if (port_int64 == 0 || port_int64 > 65535) | ||||
i_fatal("Invalid port: %"PRId64, port_int64); | ||||
port = (in_port_t)port_int64; | ||||
} | ||||
ret = net_gethostbyname(argv[1], &ips, &ips_count); | ret = net_gethostbyname(host, &ips, &ips_count); | |||
if (ret != 0) { | if (ret != 0) { | |||
i_fatal("Host %s lookup failed: %s", argv[1], | i_fatal("Host %s lookup failed: %s", host, | |||
net_gethosterror(ret)); | net_gethosterror(ret)); | |||
} | } | |||
if ((fd = net_connect_ip(&ips[0], port, NULL)) == -1) | if ((fd = net_connect_ip(&ips[0], port, NULL)) == -1) | |||
i_fatal("connect(%s, %u) failed: %m", argv[1], port); | i_fatal("connect(%s, %u) failed: %m", host, port); | |||
i_info("Connected to %s port %u.", net_ip2addr(&ips[0]), port); | i_info("Connected to %s port %u.", net_ip2addr(&ips[0]), port); | |||
i_zero(&client); | i_zero(&client); | |||
client.fd = fd; | client.fd = fd; | |||
fd_set_nonblock(STDIN_FILENO, TRUE); | fd_set_nonblock(STDIN_FILENO, TRUE); | |||
client.stdin_input = i_stream_create_fd(STDIN_FILENO, SIZE_MAX); | client.stdin_input = i_stream_create_fd(STDIN_FILENO, SIZE_MAX); | |||
client.input = i_stream_create_fd(fd, SIZE_MAX); | client.input = i_stream_create_fd(fd, SIZE_MAX); | |||
client.output = o_stream_create_fd(fd, 0); | client.output = o_stream_create_fd(fd, 0); | |||
o_stream_set_no_error_handling(client.output, TRUE); | o_stream_set_no_error_handling(client.output, TRUE); | |||
skipping to change at line 265 | skipping to change at line 270 | |||
master_service_run(master_service, NULL); | master_service_run(master_service, NULL); | |||
io_remove(&client.io_client); | io_remove(&client.io_client); | |||
io_remove(&client.io_server); | io_remove(&client.io_server); | |||
i_stream_unref(&client.stdin_input); | i_stream_unref(&client.stdin_input); | |||
i_stream_unref(&client.input); | i_stream_unref(&client.input); | |||
o_stream_unref(&client.output); | o_stream_unref(&client.output); | |||
if (close(fd) < 0) | if (close(fd) < 0) | |||
i_fatal("close() failed: %m"); | i_fatal("close() failed: %m"); | |||
} | } | |||
#else | #else | |||
static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) | static void | |||
cmd_dump_imapzlib(const char *path ATTR_UNUSED, | ||||
const char *const *args ATTR_UNUSED) | ||||
{ | { | |||
i_fatal("Dovecot compiled without zlib support"); | i_fatal("Dovecot compiled without zlib support"); | |||
} | } | |||
static void cmd_zlibconnect(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) | static void cmd_zlibconnect(struct doveadm_cmd_context *cctx ATTR_UNUSED) | |||
{ | { | |||
i_fatal("Dovecot compiled without zlib support"); | i_fatal("Dovecot compiled without zlib support"); | |||
} | } | |||
#endif | #endif | |||
struct doveadm_cmd_dump doveadm_cmd_dump_zlib = { | struct doveadm_cmd_dump doveadm_cmd_dump_zlib = { | |||
"imapzlib", | "imapzlib", | |||
test_dump_imapzlib, | test_dump_imapzlib, | |||
cmd_dump_imapzlib | cmd_dump_imapzlib | |||
}; | }; | |||
struct doveadm_cmd doveadm_cmd_zlibconnect = { | struct doveadm_cmd_ver2 doveadm_cmd_zlibconnect = { | |||
cmd_zlibconnect, | .name = "zlibconnect", | |||
"zlibconnect", | .cmd = cmd_zlibconnect, | |||
"<host> [<port>]" | .usage = "<host> [<port>]", | |||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_PARAM('\0', "host", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAM('\0', "port", CMD_PARAM_INT64, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
End of changes. 14 change blocks. | ||||
20 lines changed or deleted | 31 lines changed or added |