imap-zlib-plugin.c revision 6e7148add3f1ae3c01085eec547d3920e4c05592
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenconst char *imap_zlib_plugin_version = DOVECOT_VERSION;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic void (*next_hook_client_created)(struct client **client);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic MODULE_CONTEXT_DEFINE_INIT(imap_zlib_imap_module,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenstatic void client_skip_line(struct client *client)
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen const unsigned char *data;
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen data = i_stream_get_data(client->input, &data_size);
bd20ef9d5c639faf470912ab94e6e6627d3eaebaTimo Sirainen else if (data[0] == '\r' && data_size > 1 && data[1] == '\n')
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic void client_update_imap_parser_streams(struct client *client)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen for (cmd = client->command_queue; cmd != NULL; cmd = cmd->next) {
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainenstatic bool cmd_compress(struct client_command_context *cmd)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen struct zlib_client *zclient = IMAP_ZLIB_IMAP_CONTEXT(client);
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen unsigned int level;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* <mechanism> */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen client_send_command_error(cmd, "Invalid arguments.");
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "NO [COMPRESSIONACTIVE] COMPRESSION=%s already enabled.",
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen "NO [COMPRESSIONACTIVE] TLS compression already enabled.");
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen handler = zlib_find_zlib_handler(t_str_lcase(mechanism));
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (handler == NULL || handler->create_istream == NULL) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen client_send_tagline(cmd, "NO Unknown compression mechanism.");
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen client_send_tagline(cmd, "OK Begin compression.");
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen "imap_zlib_compress_level");
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen if (value == NULL || str_to_uint(value, &level) < 0 ||
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen client->input = handler->create_istream(old_input, FALSE);
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen client->output = handler->create_ostream(old_output, level);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic void imap_zlib_client_created(struct client **clientp)
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen if (mail_user_is_plugin_loaded(client->user, imap_zlib_module) &&
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen zclient = p_new(client->pool, struct zlib_client, 1);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen MODULE_CONTEXT_SET(client, imap_zlib_imap_module, zclient);
cd2ed64888b42b481cde6bb9548c8520516fa3e9Timo Sirainen str_append(client->capability_string, " COMPRESS=DEFLATE");
e6b4168ba670d9e51ea7877661def039ae6b53c3Timo Sirainenvoid imap_zlib_plugin_init(struct module *module)
e6b4168ba670d9e51ea7877661def039ae6b53c3Timo Sirainen command_register("COMPRESS", cmd_compress, 0);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen next_hook_client_created = hook_client_created;
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainen hook_client_created = imap_zlib_client_created;
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen hook_client_created = next_hook_client_created;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenconst char *imap_zlib_plugin_dependencies[] = { "zlib", NULL };